-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Attributes rather than am- prefix? #4
Comments
Thanks @fvsch, its really good to see this collated here. I think our specification should suggest usage of On
|
Perhaps it would be an option to have language that says something like:
Food for thought. :) (I’m not writing anything about the Component-etc. parts here, because I’m not sure what’s your plan for that.) |
👍 Great stuff @fvsch |
I agree |
I think we can close this issue for now. Pretty happy with where we landed on it. |
This is part of the feedback I emailed Glen earlier this week.
Custom Attributes?
This may be bikeshedding but I was not a fan of the
am-
prefix, partly because it reads like the “am” in “I am” or like “A.M.”, and partly because the name “Attribute Modules” doesn’t sound right to me and I would have expected “Module Attributes”, grammatically speaking. I guess “Attribute Modules” work as the name for a methodology, but as the name for a specific HTML idiom, I’m not sure.So this got me thinking, why not shoot for the stars and try to get Custom Attributes?
The basic idea for Custom Attributes is to allow as standard — and to begin with, as a well-known coding practice — the use of arbitrary HTML attribute names that follow this pattern:
someprefix-whatever
prefix-what-ever
Basically anything matching:
/[a-z]+-[a-z\d-]+/
Or reusing the language from Custom Elements:
(Okay I’m not well versed in the formal language that the XML spec uses so I’m not exactly sure what NCName allows. Maybe it’s too permissive.)
The convention for “native” HTML attributes is to use
/[a-z]+/i
, with no hyphen. This is confirmed, as far as I know, by all “HTML5” attribute names, such ascontenteditable
,contextmenu
orsrcset
(two-word names don’t use an hyphen or any separator).There are a few exceptions in existing HTML attributes, mostly HTML 1–3 legacy stuff. These could be listed as explicit exceptions. The Custom Elements spec does it for element names from the handful of SVG and MathML elements which contain an hyphen. So we could say:
(Thankfully it’s a short list. I used MDN as a reference, limiting the scope to HTML.)
Recently for ReMarkdown I’ve used a
data-rmd="some-option another-option"
attribute. With a “custom attributes” community standard, I could pick a different attribute name such as:x-remarkdown="…"
rmd-options="…"
am-remarkdown="…"
am-rmd="…"
r-md="…"
The obvious option,
remarkdown="…"
, would still be considered “illegal”; a bad practice because of a risk (albeit really small in this specific case) of colliding with a future standard attribute.Custom attributes become more obviously useful when you have several attributes for your module which all use a prefix. Currently I’m building a library whose prefix is
pcards
, so I could usepcards-color
,pcards-size
,pcards-type
instead of thedata-color
,data-size
etc. that I’m currently using (and which pose more of a risk of collision with other libs). Or justpc-color
,pc-size
,pc-type
if I want something shorter.Likely objections
Just noting some likely objections to both your proposal and my limited suggestion.
data-*
”. True. People could just usedata-mymodule
anddata-mymodule-someparam
. Custom attributes would allow to separatedata-*
stuff that is data relevant to the content from module-scoped styling and behavior hooks. Alsomymodule-x
andmymodule-someparam
are shorter than theirdata-mymodule-*
equivalents. :)The text was updated successfully, but these errors were encountered: