-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Correct hx-verb leaving behind empty class
attributes on elements
#2683
base: dev
Are you sure you want to change the base?
Conversation
Add JavaScript Jabber htmx 2.0 Spiro Floropoulos Software Unscripted ThePrimeTime TKYT
Add `elt.classList.length === 0 && elt.removeAttribute('class')` to remove empty class attributes left behind
Add `elt.classList.length === 0 && elt.removeAttribute('class')` to remove empty class attributes left behind
Add `elt.classList.length === 0 && elt.removeAttribute('class')` to remove empty class attributes left behind
Add `elt.classList.length === 0 && elt.removeAttribute('class')` to remove empty class attributes left behind
Add `elt.classList.length === 0 && elt.removeAttribute('class')` to remove empty class attributes left behind
Technically I could have just rewritten the line in |
Hey,
|
I should target
Ouch, went overboard there.
Can do as soon as I figure out how to change that in GH. |
Changes should not have been made in dist/
Changes should not be made in dist/
Changes should not be made in dist/
Changes should not be made in dist/
Replaced all element.classList add/remove methods with addClassToElement/RemoveClassFromElement
Replace all direct `classList` add/remove calls with htmx's own `addClassToElement`/`removeClassFromElement` methods, ensuring housecleaning of empty `class` elements left behind by remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated commit per requests to
- Normalize replacement across the codebase
- Target
dev
instead ofmaster
- Remove changes to files in
dist/
I commented after two lines that the original code used |
Hey @duanemoody I think this PR needs a restart, the |
Description
Manually added check for empty class to
doSettle()
after it removes its own classes:elt.classList.length === 0 && elt.removeAttribute('class')
Corresponding issue:
#1701 reporting empty
class
attributes left behind after hx-verb actions. Other functions in htmx.js doclassList.length
checks butdoSettle
doesn't leverage any of them, so per the HTML spec empty class attributes are left behind.Testing
I ran the modified code on elements with and without existing classes, and it behaved as expected: if existing class attributes were present with values, hx-put left them as-is; if no class attribute was present, none was left behind.
Checklist
master
for website changes,dev
forsource changes)
approved via an issue
npm run test
) and verified that it succeeded