File tree 2 files changed +22
-1
lines changed
2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,8 @@ import {dispatchEvent} from '../dispatchEvent'
3
3
import { behavior } from './registry'
4
4
5
5
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
7
8
if ( control ) {
8
9
return ( ) => {
9
10
if ( isFocusable ( control ) ) {
Original file line number Diff line number Diff line change @@ -191,6 +191,26 @@ test('multi touch does not click', async () => {
191
191
expect ( getEvents ( 'click' ) ) . toHaveLength ( 0 )
192
192
} )
193
193
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
+
194
214
describe ( 'check/uncheck control per click' , ( ) => {
195
215
test ( 'clicking changes checkbox' , async ( ) => {
196
216
const { element} = setup ( '<input type="checkbox" />' )
You can’t perform that action at this time.
0 commit comments