File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 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'
33import { behavior } from './registry'
44
55behavior . 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 ) ) {
Original file line number Diff line number Diff 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+
194214describe ( 'check/uncheck control per click' , ( ) => {
195215 test ( 'clicking changes checkbox' , async ( ) => {
196216 const { element} = setup ( '<input type="checkbox" />' )
You can’t perform that action at this time.
0 commit comments