A property decorator which creates a reactive property that reflects a corresponding attribute value. When a decorated property is set the element will update and render. A PropertyDeclaration may optionally be supplied to configure property features.
Import
import { property } from'lit/decorators.js';
Signature
property(options?): (protoOrDescriptor: Object | ClassElement, name?: PropertyKey) => any
This decorator should only be used for public fields. As public fields, properties should be considered as primarily settable by element users, either via attribute or the property itself. Generally, properties that are changed by the element should be private or protected fields and should use the state decorator. However, sometimes element code does need to set a public property. This should typically only be done in response to user interaction, and an event should be fired informing the user; for example, a checkbox sets its checked property when clicked and fires a changed event. Mutating public properties should typically not be done for non-primitive (object or array) properties. In other cases when an element needs to manage state, a private property decorated via the state decorator should be used. When needed, state properties can be initialized via public properties to facilitate complex interactions.
A property decorator that converts a class property into a getter that returns the assignedElements of the given slot. Provides a declarative way to use HTMLSlotElement.assignedElements.
A property decorator that converts a class property into a getter that returns a promise that resolves to the result of a querySelector on the element's renderRoot done after the element's updateComplete promise resolves. When the queried property may change with element state, this decorator can be used instead of requiring users to await the updateComplete before accessing the property.
Import
import { queryAsync } from'lit/decorators.js';
Signature
queryAsync(selector): (protoOrDescriptor: ReactiveElement | ClassElement, name?: PropertyKey) => any
Parameters
selector
string
A DOMString containing one or more selectors to match.
Declares a private or protected reactive property that still triggers updates to the element when it changes. It does not reflect from the corresponding attribute.
Import
import { state } from'lit/decorators.js';
Signature
state(options?): (protoOrDescriptor: Object | ClassElement, name?: PropertyKey) => any
Properties declared this way must not be used from HTML or HTML templating systems, they're solely for properties internal to the element. These properties may be renamed by optimization tools like closure compiler.
A function that indicates if a property should be considered changed when it is set. The function should take the newValue and oldValue and return true if an update should be requested.