Skip to content

Commit ca4482a

Browse files
authored
fix(pointer): consider click context (#850)
1 parent 214fd03 commit ca4482a

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/event/behavior/click.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {dispatchEvent} from '../dispatchEvent'
33
import {behavior} from './registry'
44

55
behavior.click = (event, target, config) => {
6-
const control = target.closest('label')?.control
6+
const context = target.closest('button,input,label,textarea')
7+
const control = context && isElementType(context, 'label') && context.control
78
if (control) {
89
return () => {
910
if (isFocusable(control)) {

tests/pointer/click.ts

+20
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,26 @@ test('multi touch does not click', async () => {
191191
expect(getEvents('click')).toHaveLength(0)
192192
})
193193

194+
describe('label', () => {
195+
test('click associated control per label', async () => {
196+
const {element, getEvents} = setup(
197+
`<label for="in">foo</label><input id="in"/>`,
198+
)
199+
200+
await userEvent.pointer({keys: '[MouseLeft]', target: element})
201+
202+
expect(getEvents('click')).toHaveLength(2)
203+
})
204+
205+
test('click nested control per label', async () => {
206+
const {element, getEvents} = setup(`<label><input/></label>`)
207+
208+
await userEvent.pointer({keys: '[MouseLeft]', target: element})
209+
210+
expect(getEvents('click')).toHaveLength(2)
211+
})
212+
})
213+
194214
describe('check/uncheck control per click', () => {
195215
test('clicking changes checkbox', async () => {
196216
const {element} = setup('<input type="checkbox" />')

0 commit comments

Comments
 (0)