feat(hx-live): support boolean attribute binding with :?attr (#4019) - #4022
Open
AndrewGit25 wants to merge 1 commit into
Open
feat(hx-live): support boolean attribute binding with :?attr (#4019)#4022AndrewGit25 wants to merge 1 commit into
AndrewGit25 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds support for an explicit boolean attribute binding modifier—
:?<attr>and its canonical formhx-live:?<attr>—tohx-live.While
hx-livetoggles native boolean attributes (disabled,required, etc.) based on truthiness, generic attributes stringify booleans (e.g.:multiple="false"writesmultiple="false"). For Web Components (like Lit's@property({ type: Boolean })), Custom Elements, and custom boolean attributes where attribute presence dictates state rather than string value, this caused attributes to remain present when falsy.Borrowing the
?prefix convention from Lit and the Web Components ecosystem:true, non-empty strings, positive numbers) add/retain the attribute via nativetoggleAttribute().false,null,undefined,0,"") remove the attribute entirely via nativetoggleAttribute().Example:
Corresponding issue: Closes #4019
Testing
test/tests/ext/hx-live.jscovering:?attr,hx-live:?attr, and truthy/falsy evaluation rules.npm run test(all 1,739 tests passed across 87 test files with 100% code coverage).npm run check:content(all doc and API checks passed).test/scratch/scratch.htmlwith real-time DOM mutation inspection on custom web components and standard elements.Checklist
masterfor website changes,devforsource changes)
hx-live: Support Boolean Attribute Binding (:?attr/hx-live:?attr) for Custom Attributes & Web Components #4019npm run test) and verified that it succeeded