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

Value defaults not committed to DOM #580

Closed
adrolter opened this issue Sep 2, 2022 · 5 comments
Closed

Value defaults not committed to DOM #580

adrolter opened this issue Sep 2, 2022 · 5 comments

Comments

@adrolter
Copy link

adrolter commented Sep 2, 2022

Would it make sense to always write value defaults to their respective DOM attributes when the controller loads, as is done on write to a value property? I currently have to remember to explicitly write them in connect with this.someValue = this.constructor.values.some.default for every such value to achieve this behavior.

If this feature is desired I'd be happy to implement it. Thanks!

@lb-
Copy link
Contributor

lb- commented Sep 2, 2022

Just curious why you need this?

I've always resolved that the defaults are there for when there is no explicit value set.

This would potentially impact some performance for larger sets of default values. Also it would trigger false positives on valueChanged callbacks.

@marcoroth
Copy link
Member

marcoroth commented Sep 2, 2022

Hey @adrianguenter, thanks for opening this issue!

I remember thinking about this while implementing #350. The reason why I opted not to write the default Values to the DOM was to make sure that the this.has[name]Value keeps it's relevance.

What's your use case for this? Do you need to read the attributes from somewhere else?

The thing we need to think about is "does having a default value mean that we have a value"?

@adrolter
Copy link
Author

adrolter commented Sep 2, 2022

Thanks for the input! My use case is that I drive CSS with these attributes, and therefore need the default values to be reflected in the DOM.

@lb-
Copy link
Contributor

lb- commented Sep 2, 2022

Even if you do set the value in JS on load - this approach could cause a flash of the unstyled (no data attribute) content.

Hence you would be best to add the default styles case in your css (e.g. element :not([data-my-foo-value])).

Once you have default styles for when the value is not set - you don't need to worry about default attribute setting.

@adrolter
Copy link
Author

adrolter commented Sep 2, 2022

@lb- That's a good approach I hadn't considered and should, in principle, suit my needs. Thank you!

@adrolter adrolter closed this as completed Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants