Skip to content

unify hx-on and hx-trigger modifier grammar2#3805

Open
MichaelWest22 wants to merge 7 commits into
bigskysoftware:four-devfrom
MichaelWest22:hx-on2
Open

unify hx-on and hx-trigger modifier grammar2#3805
MichaelWest22 wants to merge 7 commits into
bigskysoftware:four-devfrom
MichaelWest22:hx-on2

Conversation

@MichaelWest22
Copy link
Copy Markdown
Collaborator

@MichaelWest22 MichaelWest22 commented May 19, 2026

Description

Built some changes on top of the great work in #3798

Changes @scriptogre made:

enable hx-on="triggerSpec -> code" syntax that supports all existing hx-trigger modifiers (e.g. [filter], once, delay, changed, from, etc.).

add new modifiers to both hx-on and hx-trigger: prevent, stop, halt, capture, passive, from:self, from:outside

remove undocumented dot modifiers (.prevent, .stop, .halt, .once, .self, .outside, .capture, .passive, .cc) from hx-on:event syntax

remove hx-trigger queue modifier from docs (no-op in 4.0)

update tests, docs, and extension references

Changes I've made on top:

reverted the triggerSpec -> eventSpec and onTrigger -> onEvent renames. I feel that the old trigger name is clearer here and more understood. these specs and handling can be non event based like load, intersect etc and can have modifiers in how they trigger over just a pure event based action so I think Trigger is still the right name for them both.

improved the JS handling and splitting of the triggerSpec -> code using a simple regex. with -> as the new seperator it does not conflict with JS syntax and we can use the ; at the end to identify chained triggerSpec's cleanly now.

Simplified the onTrigger() function to use less deeply nested chained callbacks. Found that the reworked hx-on . modifiers had a simpler handler design and we can reuse this in onTrigger to cut out much of the code complexity and just leave the things like delay etc that have to stay as handler wrappers.

Also added in rootMargin support to the IntersectionObserver which is only one line to add now which is easy. #1349 #2593 #3802

scriptogre and others added 7 commits May 14, 2026 16:36
- enable hx-on="eventSpec => code" syntax that supports all existing hx-trigger modifiers (e.g. [filter], once, delay, changed, from, etc.).

- add new modifiers to both hx-on and hx-trigger: prevent, stop, halt, capture, passive, from:self, from:outside
- remove undocumented dot modifiers (.prevent,
.stop, .halt, .once, .self, .outside, .capture, .passive, .cc) from hx-on:event syntax
- rename __onTrigger -> __onEvent
- rename __parseTriggerSpecs -> __parseEventSpecs
- remove hx-trigger queue modifier from docs (no-op in 4.0)
- update tests, docs, and extension references
Change the grammar separator in hx-on="event => code" from => to ->.
This avoids visual ambiguity with JavaScript arrow functions that may
appear in the handler code.

Updated:
- src/htmx.js: indexOf('=>') → indexOf('->')
- test/tests/attributes/hx-on.js: all hx-on attribute values
- test/tests/ext/hx-live.js: hx-live helper tests using hx-on
- www docs: all examples and explanations in hx-on.md
- enable hx-on="eventSpec => code" syntax that supports all existing hx-trigger modifiers (e.g. [filter], once, delay, changed, from, etc.).

- add new modifiers to both hx-on and hx-trigger: prevent, stop, halt, capture, passive, from:self, from:outside
- remove undocumented dot modifiers (.prevent,
.stop, .halt, .once, .self, .outside, .capture, .passive, .cc) from hx-on:event syntax
- rename __onTrigger -> __onEvent
- rename __parseTriggerSpecs -> __parseEventSpecs
- remove hx-trigger queue modifier from docs (no-op in 4.0)
- update tests, docs, and extension references
Change the grammar separator in hx-on="event => code" from => to ->.
This avoids visual ambiguity with JavaScript arrow functions that may
appear in the handler code.

Updated:
- src/htmx.js: indexOf('=>') → indexOf('->')
- test/tests/attributes/hx-on.js: all hx-on attribute values
- test/tests/ext/hx-live.js: hx-live helper tests using hx-on
- www docs: all examples and explanations in hx-on.md
@MichaelWest22 MichaelWest22 changed the title unify hx-on and hx-trigger modifier grammar unify hx-on and hx-trigger modifier grammar2 May 19, 2026
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.

2 participants