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

color vs value attribute #73

Open
LeaVerou opened this issue May 29, 2024 · 5 comments
Open

color vs value attribute #73

LeaVerou opened this issue May 29, 2024 · 5 comments

Comments

@LeaVerou
Copy link
Member

LeaVerou commented May 29, 2024

When rewriting <color-swatch>, I opted for a color attribute. However, I’m not so sure it was a good idea. value is far more common across HTML elements, and there are libraries and frameworks that work out of the box with elements that follow the convention of .value property + input event for user-initiated changes (e.g. Vue’s v-model). Also, color is a Color, so conceptually since the attribute is specifying a string, value seems more fitting.

So what about:

  • value attribute, which gets reflected into a value property
  • color property that contains a Color instance if this.value is a valid color, or null otherwise.

This would be across all components whose value is a color (<color-inline>, <color-swatch>, <color-picker>).

@DmitrySharabin
Copy link
Member

DmitrySharabin commented May 30, 2024

Do I get it correctly that the color property will become a getter in that case? Can authors set Color as a value of the value attribute?

In general, I think it's good to be consistent with the platform and let authors use the elements the way they used to. I think it's a win-win.

@LeaVerou
Copy link
Member Author

No, I think it's okay for authors to set either of them, and they should be kept in sync.

I was also thinking that space has a similar issue: Authors actually set a space id via the attribute, but it gets converted to a color space object. We should instead have a spaceId property (that reflects from the space attribute) and a separate space property that is a ColorSpace object (and authors can set either).

@LeaVerou
Copy link
Member Author

For inspiration, I was using <input>’s valueAsDate/valueAsNumber properties, and that's exactly how they work: https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement

@DmitrySharabin
Copy link
Member

I was also thinking that space has a similar issue: Authors actually set a space id via the attribute, but it gets converted to a color space object.

I believe we have a bit more, e.g., stops.

@LeaVerou
Copy link
Member Author

LeaVerou commented Jun 6, 2024

Related: nudeui/element#24

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

2 participants