@@ -463,4 +463,98 @@ describe('InternalFrequencyControl', () => {
463463 expect ( input ) . to . have . property ( 'value' , '2' ) ;
464464 expect ( select ) . to . have . property ( 'value' , 'times_a_month' ) ;
465465 } ) ;
466+
467+ it ( 'focuses input when clicking outside INPUT and LABEL in summary-item layout' , async ( ) => {
468+ const layout = html `< test-internal-frequency-control
469+ layout ="summary-item "
470+ > </ test-internal-frequency-control > ` ;
471+ const control = await fixture < TestControl > ( layout ) ;
472+
473+ const input = control . renderRoot . querySelector ( 'vaadin-integer-field' ) ?. querySelector ( 'input' ) ;
474+ if ( ! input ) return ; // Skip if input not found
475+
476+ const focusStub = stub ( input , 'focus' ) ;
477+
478+ const mockEvent = new MouseEvent ( 'click' , { bubbles : true } ) ;
479+ Object . defineProperty ( mockEvent , 'composedPath' , {
480+ value : ( ) => [ control ] ,
481+ } ) ;
482+
483+ // @ts -expect-error accessing protected member for testing purposes
484+ control . _handleHostClick ( mockEvent ) ;
485+
486+ expect ( focusStub ) . to . have . been . calledOnce ;
487+
488+ focusStub . restore ( ) ;
489+ } ) ;
490+
491+ it ( 'does not focus input when layout is not summary-item' , async ( ) => {
492+ const layout = html `< test-internal-frequency-control > </ test-internal-frequency-control > ` ;
493+ const control = await fixture < TestControl > ( layout ) ;
494+
495+ const input = control . renderRoot . querySelector ( 'input' ) ;
496+ const focusStub = input ? stub ( input , 'focus' ) : null ;
497+
498+ const mockEvent = new MouseEvent ( 'click' , { bubbles : true } ) ;
499+ Object . defineProperty ( mockEvent , 'composedPath' , {
500+ value : ( ) => [ control ] ,
501+ } ) ;
502+
503+ // @ts -expect-error accessing protected member for testing purposes
504+ control . _handleHostClick ( mockEvent ) ;
505+
506+ if ( focusStub ) {
507+ expect ( focusStub ) . to . not . have . been . called ;
508+ focusStub . restore ( ) ;
509+ }
510+ } ) ;
511+
512+ it ( 'does not focus input when clicking on INPUT element' , async ( ) => {
513+ const layout = html `< test-internal-frequency-control
514+ layout ="summary-item "
515+ > </ test-internal-frequency-control > ` ;
516+ const control = await fixture < TestControl > ( layout ) ;
517+
518+ const input = control . renderRoot . querySelector ( 'vaadin-integer-field' ) ?. querySelector ( 'input' ) ;
519+ if ( ! input ) return ;
520+
521+ const focusStub = stub ( input , 'focus' ) ;
522+
523+ const mockEvent = new MouseEvent ( 'click' , { bubbles : true } ) ;
524+ Object . defineProperty ( mockEvent , 'composedPath' , {
525+ value : ( ) => [ input ] ,
526+ } ) ;
527+
528+ // @ts -expect-error accessing protected member for testing purposes
529+ control . _handleHostClick ( mockEvent ) ;
530+
531+ expect ( focusStub ) . to . not . have . been . called ;
532+
533+ focusStub . restore ( ) ;
534+ } ) ;
535+
536+ it ( 'does not focus input when clicking on LABEL element' , async ( ) => {
537+ const layout = html `< test-internal-frequency-control
538+ layout ="summary-item "
539+ > </ test-internal-frequency-control > ` ;
540+ const control = await fixture < TestControl > ( layout ) ;
541+
542+ const input = control . renderRoot . querySelector ( 'vaadin-integer-field' ) ?. querySelector ( 'input' ) ;
543+ if ( ! input ) return ;
544+
545+ const focusStub = stub ( input , 'focus' ) ;
546+ const label = document . createElement ( 'label' ) ;
547+
548+ const mockEvent = new MouseEvent ( 'click' , { bubbles : true } ) ;
549+ Object . defineProperty ( mockEvent , 'composedPath' , {
550+ value : ( ) => [ label ] ,
551+ } ) ;
552+
553+ // @ts -expect-error accessing protected member for testing purposes
554+ control . _handleHostClick ( mockEvent ) ;
555+
556+ expect ( focusStub ) . to . not . have . been . called ;
557+
558+ focusStub . restore ( ) ;
559+ } ) ;
466560} ) ;
0 commit comments