Skip to content
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

Discussion issue for attribute mappings #4

Open
domenic opened this issue Apr 26, 2019 · 10 comments
Open

Discussion issue for attribute mappings #4

domenic opened this issue Apr 26, 2019 · 10 comments

Comments

@domenic
Copy link
Contributor

domenic commented Apr 26, 2019

https://github.com/tkent-google/std-switch/tree/3418f78239e5a99ca6c37099ecb3edfc45e21b29#content-attributes discusses two models for attribute mappings. Here I will list some pros/cons.

A) Compatible with <input type=checkbox>

  • (+) Consistent, and thus relatively easy to understand, especially for reset behavior.
  • (+) Easy to refactor between checkboxes and switches. (Is this important?)
  • (-) Historically, the checked="" <-> defaultChecked and nothing <-> checked behavior has been quite confusing for developers. Some frameworks have worked to hide it. Maybe we should not propagate it.

B) Simple mappings

  • (+) Simpler mental model, matching 99% of all HTML attribute mappings
  • (+) Allows styling based off of attributes, e.g. #my-switch[checked], instead of pseudo-classes. See Pseudo class for state: should it be :checked? #3. (I think this is a pro because it removes the footgun of trying to use attribute selectors and it only working for default checkedness.)
  • (+) More generally, storing state in the tree instead of internally makes various operations, e.g. cloning or serializing, simpler for developers.
  • (-) The usage of defaultchecked="" can be a bit confusing. Especially because you could write <std-switch defaultchecked> (with no checked="" attribute) where it is not checked "by default". Maybe we could fix this by renaming it to checkedafterreset=""?

I think this issue would benefit a lot from web developer feedback.

@matthewp
Copy link

matthewp commented Jun 7, 2019

Not sure what sort of feedback is wanted here, but I would favor (B) primarily for the advantage of styling. This type of element in particular is one where you might want to style it differently depending on the checked state. I have used this pattern of a boolean attribute quite a bit in my own custom elements, such as this drop down menu that does exactly the same thing for styling purposes.

@domenic
Copy link
Contributor Author

domenic commented Jun 7, 2019

Styling should be possible in either; if we did (A) then either :checked or :state(on) or similar would be used. See #3.

@bathos
Copy link

bathos commented Jun 7, 2019

I would prefer A given the attribute names are checked/defaultChecked because the improved ergonomics of B don’t trump the reduced er ... meta ergonomics ... of having to remember an exception to an exception. I know "HTMLInputElement.prototype.checked" and ""HTMLSwitchElement.prototype.checked" would not be the same content attribute technically, but from a dev perspective there will probably be a reasonable expectation that "input elements that have the checked + defaultChecked interface do x".

@domenic
Copy link
Contributor Author

domenic commented Jun 7, 2019

Thanks @bathos!

Do you think it'd be different if we used "on" instead of "checked"? See #2.

@TimvdLippe
Copy link

@bathos
Copy link

bathos commented Jun 7, 2019

Yes — it’s the common naming that makes it a footgun from my POV if they behave differently, not the different behavior itself.

@justinfagnani
Copy link

I think (B) is preferable if we assume that there will eventually be a larger, more actively used, set of new controls than the current built-in set. Then we can establish a new norm, and the existing elements will be the exception.

@ghost
Copy link

ghost commented Jun 17, 2019

+1 for (B) with "on" instead of "checked". Drawing a parallel with physical switches, you don't check them, you turn them on/off.

@tkent-google
Copy link
Owner

At this moment, my conclusion is (B) with on.

If we implemented the switch control as <input type=switch>, we should follow the existing convention. However we'd like to introduce new element and we don't need to follow the confusing convention. Also, form reset is rarely used and the weirdness of defaultchecked in (B) doesn't matter.

I'll update the explainer for (B) with 'on', but I'll keep this issue open because I might change my mind. 🤔

tkent-google added a commit that referenced this issue Jun 19, 2019
- Apply simple reflection to on/defaulton; #4
- Change checked/defaultChecked to on/defaultOn; #2
- Add some links to issues
@cartr
Copy link

cartr commented Jul 27, 2019

Custom elements can inherit from built-in ones, can't they? If users could write something like <input type="checkbox" is="std-switch" /> to fall back to a checkbox when std-switch isn't available (or JavaScript is disabled), that'd be a pretty big advantage of of (A).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants