Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can custom elements' attributes be camelCased?

I have a custom element with attributes:

class MyElement extends HTMLElement {
    ...
    static get observedAttributes() {
        return ["camelCaseAttribute"];
    }

    set camelCaseAttribute(a) {
        this._a = a;
    }
    ...
 }

I use it in my HTML like so:

<my-element camelCaseAttribute="blubb"></my-element>

The attribute camelCaseAttribute is not set when writing it in camelCase, but writing it without upper-case-letters works. Why?

like image 925
treeno Avatar asked Jun 03 '17 19:06

treeno


People also ask

Can I use form associated custom elements?

Form-associated custom elements # You can use the event-based API with any kind of component, but it only allows you to interact with the submission process. Standardized form controls participate in many parts of the form lifecycle besides submission.

What are autonomous custom elements?

Autonomous custom elements are new HTML tags, defined entirely by the author. They have none of the semantics of existing HTML elements, so all behaviors need to be defined by the author. Customized built-ins extend existing HTML elements with custom functionality. They inherit semantics from the elements they extend.

How do custom elements work?

Custom Elements are a feature of modern browsers which allow you to modularise and install your JavaScript components into the browser itself in order to extend it in new and powerful ways. Custom Elements are HTML components which have their own self-contained markup, styling and behaviour.


1 Answers

In the HTML Living Standard, Section 4.13.3 Core Concepts:

4.13.3 Core concepts

Any namespace-less attribute that is relevant to the element's functioning, as determined by the element's author, may be specified on an autonomous custom element, so long as the attribute name is XML-compatible and contains no ASCII upper alphas. The exception is the is attribute, which must not be specified on an autonomous custom element (and which will have no effect if it is).

It is defined in the HTML Living Standard that a custom element's namespace-less attributes must be XML-compatible with no ASCII uppercase letters, thus your attributes cannot be camelCased.

like image 91
Andrew Li Avatar answered Sep 28 '22 04:09

Andrew Li