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

fix(click): skip explicit re-dispatch for face #1238

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/event/behavior/click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import {behavior} from './registry'
behavior.click = (event, target, instance) => {
const context = target.closest('button,input,label,select,textarea')
const control = context && isElementType(context, 'label') && context.control
if (control) {
if (
control &&
!(control.constructor as {formAssociated?: boolean}).formAssociated
) {
return () => {
if (isFocusable(control)) {
focusElement(control)
Expand Down
22 changes: 22 additions & 0 deletions tests/pointer/click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,28 @@ describe('label', () => {

expect(getEvents('click')).toHaveLength(2)
})

// TODO: enable as soon as jsdom properly supports CEs
test.skip('click nested FACE per label', async () => {
const {elements, getEvents, user} = setup(`
<script>
class FaCe extends HTMLElement {
static formAssociated = true;
}
customElements.define("fa-ce", FaCe);
</script>
<label>
<fa-ce></fa-ce>
</label>
`)

await user.pointer({
keys: '[MouseLeft]',
target: Array.from(elements).at(-1),
})

expect(getEvents('click')).toHaveLength(2)
})
})

describe('check/uncheck control per click', () => {
Expand Down