-
Notifications
You must be signed in to change notification settings - Fork 43
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
Boolean attribute doesn't behave as might by expected for web component #162
Comments
fwiw, I agree we should match the default behavior of the DOM ... attribute existence is |
Borrows some ideas from bitovi#123 Fixes bitovi#162
-_-' My bad - I didn't look through the open PRs: there's #123 addressing the same issue I raised, yet in a different way than I proposed (absence of value is checked not at the level of Some of the ideas from #123 (namely - the access to attribute name in Anyway: I created #164 that aims to resolve this issue |
I agree that it should match the DOM behaviour very closely, but we didn't realize this until after the 2.0 release and modifying it now would be a backwards-breaking change. The most confusing parts to me of DOM behaviour is that |
In #164 Maybe then, for 2.x there could be a second |
Hi!
I noticed that the chosen behaviour for boolean transform is
react-to-web-component/packages/core/src/transforms/boolean.ts
Lines 3 to 6 in 1a6886a
which is:
and it's tested:
react-to-web-component/tests/react-to-webcomponent.test.jsx
Lines 352 to 353 in 002a007
On the other hand HTML boolean (https://developer.mozilla.org/en-US/docs/Glossary/Boolean/HTML) attribute is considered
true
just because it's present:That leads to interesting behaviour - if attribute is present, but not assigned a value (i.e. it's HTML Boolean), it's cast to
false
(not justundefined
but actually the polar opposite)I detected it wile using with Lit booleans (https://lit.dev/docs/templates/expressions/#boolean-attribute-expressions) - Lit implements HTML boolean.
I think it can be resolved in a backwards compatible way.
I see that transforms are given the attribute name as 2nd argument
react-to-web-component/packages/core/src/core.ts
Line 100 in 002a007
attributeChangedCallback
react-to-web-component/packages/core/src/core.ts
Line 130 in 002a007
So parse could be made into
I don't have an idea for
stringify
, though. It would have to be a choice of the author (i.e. differently named transform) I guessThe text was updated successfully, but these errors were encountered: