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

HTML Boolean #164

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

HTML Boolean #164

wants to merge 3 commits into from

Conversation

jrencz
Copy link

@jrencz jrencz commented Jan 12, 2024

This PR makes r2wc treat prop declared as "boolean" , i.e.

const SomeElement = r2wc(Some, {
  props: {
    foo: "boolean"
  }
})

with reasonable portion of semantics of HTML Boolean attribute (as described in https://developer.mozilla.org/en-US/docs/Glossary/Boolean/HTML) so it's still as backwards compatible as possible.

If an HTML tag contains a boolean attribute - no matter the value of that attribute - the attribute is set to true on that element.

specified part is deliberately not obeyed by code I propose, as pre-existing behavior is very much different. With this PR values that were considered false before (e.g. 0, no, false, n, f, etc.) are still considered false

If an HTML tag does not contain the attribute, the attribute is set to false.

If the attribute is present, it can have one of the following values:

  • no value at all, e.g. attribute
  • the empty string, e.g. attribute=""
  • attribute's name itself, with no leading or trailing whitespace, e.g. attribute="attribute"

this part is AFAIK followed faithfully.

Warning

There's one change of behavior that's to be discussed

  • was:
    when a false is assigned to property foo mapped as "boolean" then attribute becomes foo="false"
  • will be:
    when a false is assigned to property foo mapped as "boolean" then attribute becomes taken away entirely

IMO this change should be applied, but open to making that particular change later, on upcoming 3.0, when it's time, over holding the entire thing back until then.

This one also borrows some ideas from unfinished #123 by @shoumaw (handling booleans before running transform.parse, but not the deprecation of syntax defined as ^[ty1-9]).
In fact: I ensured the current behavior with more tests - until it's actually decided that it should be dropped, I think it's worth having it secured

Fixes #162

Borrows some ideas from bitovi#123

Fixes bitovi#162
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

Successfully merging this pull request may close these issues.

Boolean attribute doesn't behave as might by expected for web component
1 participant