Fast: Attribute name naming conventions for fast-components

Created on 4 May 2020  路  7Comments  路  Source: microsoft/fast

Opening a discussion based on this discussion: https://github.com/microsoft/fast-dna/pull/3015#discussion_r419574806

I'd like to land a convention surrounding HTML attribute naming for @microsoft/fast-components. Two primary patterns:

No delineator

Native HTML generally (with a few exceptions) creates attribute names by combining lower-case words with no delineation between the words. Eg: readonly, contenteditable, formaction, etc.

Pros:

  • More native precedent
  • etc?

Hyphen-separated

Hyphen separated words in attribute names are legal in HTML, though the use of hyphens is minimal compared to the above. Examples include all of the aria- attributes, arbitrary data- attributes, accept-charset and http-equiv

Pros:

  • readability
  • spell-checking
  • etc?

Note: I've specifically left out camelCase because HTML is not case-sensitive - see https://codepen.io/rice119/pen/bGVadJZ

Most helpful comment

My $.02 - If we are providing a transparent API to existing HTML attributes or there is an existing html attribute for what we are exposing as an attribute, we should map to the attribute (example: formaction). If there is not anything pre-existing I think we should go for legibility, readability, etc. I would have a strong hesitation to changing existing html attributes to hyphen-delineated if they are not already (example: formaction => form-action).

All 7 comments

I think as we get to more complex attribute naming (more than 2 or 3 words) hypens really help break up the attribute names. Just wondering if we should retroactively and go back and fix any multiword attribute names.

Hyphens good IMO. And yes, retroactively correct while we are still in a beta phase.

I like hyphens for readability as well. Additionally, since custom element names require a hyphen to prevent conflicts with built-ins, perhaps we should also use hyphens for attributes. That feels more consistent even it it's not required.

My $.02 - If we are providing a transparent API to existing HTML attributes or there is an existing html attribute for what we are exposing as an attribute, we should map to the attribute (example: formaction). If there is not anything pre-existing I think we should go for legibility, readability, etc. I would have a strong hesitation to changing existing html attributes to hyphen-delineated if they are not already (example: formaction => form-action).

@chrisdholt agreed.

For the record, I'm also for preferring hyphens.

+1 for hyphens. In addition to the points above: being inconsistent with native attributes also makes them stand out to the end-user of these elements as something custom that may need additional attention.

I'm going to call that consensus - we can re-open if new perspectives are presented.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

limefrogyank picture limefrogyank  路  4Comments

MarcSkovMadsen picture MarcSkovMadsen  路  4Comments

eljefe223 picture eljefe223  路  6Comments

EisenbergEffect picture EisenbergEffect  路  5Comments

MarcSkovMadsen picture MarcSkovMadsen  路  6Comments