Skip to content

Commit

Permalink
✅ Allows underscore in event names (#3756)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekwoka committed Oct 18, 2023
1 parent b124ed7 commit 6cecc7d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/alpinejs/src/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ let alpineAttributeRegex = () => (new RegExp(`^${prefixAsString}([^:^.]+)\\b`))
function toParsedDirectives(transformedAttributeMap, originalAttributeOverride) {
return ({ name, value }) => {
let typeMatch = name.match(alpineAttributeRegex())
let valueMatch = name.match(/:([a-zA-Z0-9\-:]+)/)
let valueMatch = name.match(/:([a-zA-Z0-9\-_:]+)/)
let modifiers = name.match(/\.[^.\]]+(?=[^\]]*$)/g) || []
let original = originalAttributeOverride || transformedAttributeMap[name] || name

Expand Down
14 changes: 14 additions & 0 deletions tests/cypress/integration/directives/x-on.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,20 @@ test('.dot modifier correctly binds event listener',
get('span').should(haveText('baz'))
}
)
test('underscores are allowed in event names',
html`
<div x-data="{ foo: 'bar' }" x-on:event_name="foo = 'baz'">
<button x-on:click="$dispatch('event_name')"></button>
<span x-text="foo"></span>
</div>
`,
({ get }) => {
get('span').should(haveText('bar'))
get('button').click()
get('span').should(haveText('baz'))
}
)

test('.dot modifier correctly binds event listener with namespace',
html`
Expand Down

0 comments on commit 6cecc7d

Please sign in to comment.