-
Notifications
You must be signed in to change notification settings - Fork 49
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
Guidance about reflecting state in HTML attributes #501
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1032,6 +1032,25 @@ The alternative user experience is a flash of unstyled content, which is undesir | |
|
||
See also [[#worker-only]]. | ||
|
||
<h3 id="html-attribute-property-reflection">Expose content attributes for writable IDL attributes</h3> | ||
|
||
When designing a new *writable* IDL attribute to specify element state, | ||
expose a corresponding content attribute unless you have a compelling reason not to. | ||
|
||
Providing declarative ways to manipulate state has several benefits for authors: | ||
- It takes advantage of HTML’s [reactivity](https://en.wikipedia.org/wiki/Reactive_programming), and alleviates the need to apply changes at a specific moment in time. | ||
- It integrates with existing DOM methods, improving learnability, whereas an API specific to the feature needs to be learned separately. | ||
- Behaviors can be expressed reactively in libraries supporting HTML-based syntax and be handled by any library handling HTML generically. | ||
- UI states can be addressed in CSS via simple attribute selectors rather than new pseudo-classes. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if this is a good thing in all cases. For instance, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems orthogonal. In that case the pseudo-class serves a distinct purpose by targeting the actual computed language (which may be specified on an ancestor). I’d argue there may even be value in a generic attribute selector for these inherited attributes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd favor Lea's point on this one. That said, the other point is also good: |
||
- State can be inspected and manipulated via the browser's developer tools with no need for implementing a new UI. | ||
|
||
<div class="example"> | ||
A counterpattern to this guidance can be found in | ||
<{input}>'s {{HTMLInputElement/indeterminate}} IDL property | ||
which was never exposed as a content attribute making it impossible to fully update checkbox state | ||
by modifying HTML. | ||
</div> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the other hand, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you elaborate? Is it the UI of an indeterminate checkbox that you think is a mistake or the way it was added to HTML? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of the above, IIRC. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The You could argue that we should have had a (And of course people always like to point out that the IDL attributes not matching the names of the content attributes is confusing, but that's also a separate matter and anyway not something that can actually be solved.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There’s a separate, existing, principle about this: Keep attributes in sync. It’s right below this one actually 😁
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hober Interesting. Could you elaborate on the UI part? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That principle is about content attributes needing to be reflected right? But
|
||
|
||
<h3 id="html-idl-must-by-synced">Keep attributes in sync</h3> | ||
|
||
New content attributes | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The emphasis on "writable" doesn't seem to serve a purpose. (I, for one, find it distracting.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree, I think "writable" is essential to the principle and should be emphasized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest a rephrase then.