v0.14.134 - 54.6 / 40.9

attributes / properties

Describes behavior with attributes and properties.

# Attributes vs Properties

setProperty will be used when any of the following is true:

  1. the element has a dash on the tagName, as custom elements do
  2. value is object, null or undefined
  3. value is boolean and name doesnt contain hyphens

setAttribute will be also used when any of the following is true:

  1. value is not an object, null or undefined

While this does not work for every situation, it's a sensible default that works in most cases. To change this behavior see the next section

# Namespace To Force Props Type

A namespace can be used to force the prop kind

NameKindDescription
attr:namesetAttributewill always add it as an attribute
prop:namesetPropertywill always set it as a property
bool:namesetBooladds/remove based on truthy/falsy

# lit-style attributes/properties

html may use lit-style attributes/properties

NameKindDescription
.someProp="true"setPropertywill always set it as a property
?bool="value"setBooladds/remove based on truthy/falsy
@click="{handleEvent(e){...}, once:true}"EventListeneradds/remove based on truthy/falsy

See Also: attr:__, prop:__, bool:__ and setAttribute, setProperty, setBool

# Deleting

On a property, deleting means setting the value to null when the new value is null or undefined.

On an attribute, deleting means removing the attribute when the new value is null or undefined.

# Locked To Properties

value, textContent, innerText, innerHTML are locked to always use setProperty

# Children

children as an attribute will be used as long as the node on where it's defined doesn't have any childNodes. Note: children cannot be overridden via a propsPlugin. Everything else can be changed.

# xmlns

The xmlns attribute is copied to children. Which means it supports by default most kinds if not all xmls: SVG, MathML, with its fancy namespaces.

# Events

Events using the on__ form are case insensitive

Events using the on:__ form are case sensitive

# Props With Default Behavior

NameDescription
refcallback to get a reference to the element
onMountonMount adds a callback to the mount event
onUnmountonUnmount adds a callback to the unmount event
classsets classes in the element in various ways
stylesets styles in the element in various ways
varsets a css var in the element
css<span css="class{color:green} class:hover{color:red}"/> becomes <span class="class-styles-applied"/>

# SVG

test: SVG + xlink

# Showing XML Test

Testing if keeps the parent xmlns using a toggling Show