@@ -656,3 +656,77 @@ describe('value control buttons', () => {
656656 } ) ;
657657 } ) ;
658658} ) ;
659+
660+ describe ( 'multiple fields' , ( ) => {
661+ let container , fields ;
662+
663+ beforeEach ( async ( ) => {
664+ container = fixtureSync ( `
665+ <div>
666+ <vaadin-number-field step-buttons-visible></vaadin-number-field>
667+ <vaadin-number-field step-buttons-visible></vaadin-number-field>
668+ </div>
669+ ` ) ;
670+ await nextRender ( ) ;
671+ fields = [ ...container . children ] ;
672+ } ) ;
673+
674+ [ 'increase' , 'decrease' ] . forEach ( ( type ) => {
675+ describe ( `${ type } button` , ( ) => {
676+ let button ;
677+
678+ beforeEach ( ( ) => {
679+ button = fields [ 1 ] . shadowRoot . querySelector ( `[part=${ type } -button]` ) ;
680+ } ) ;
681+
682+ it ( `should blur the other field on ${ type } button touchend` , ( ) => {
683+ const input = fields [ 0 ] . inputElement ;
684+ input . focus ( ) ;
685+
686+ const spy = sinon . spy ( input , 'blur' ) ;
687+ const e = new CustomEvent ( 'touchend' , { cancelable : true } ) ;
688+ button . dispatchEvent ( e ) ;
689+
690+ expect ( spy ) . to . be . calledOnce ;
691+ } ) ;
692+
693+ it ( `should not blur the other field on ${ type } button touchend if not cancelable` , ( ) => {
694+ const input = fields [ 0 ] . inputElement ;
695+ input . focus ( ) ;
696+
697+ const spy = sinon . spy ( input , 'blur' ) ;
698+ const e = new CustomEvent ( 'touchend' , { cancelable : false } ) ;
699+ button . dispatchEvent ( e ) ;
700+
701+ expect ( spy ) . to . be . not . called ;
702+ } ) ;
703+
704+ it ( `should not blur the field on its own ${ type } button touchend` , ( ) => {
705+ const input = fields [ 1 ] . inputElement ;
706+ input . focus ( ) ;
707+
708+ const spy = sinon . spy ( input , 'blur' ) ;
709+ const e = new CustomEvent ( 'touchend' , { cancelable : true } ) ;
710+ button . dispatchEvent ( e ) ;
711+
712+ expect ( spy ) . to . be . not . called ;
713+ } ) ;
714+
715+ it ( `should not blur the field on its own ${ type } button touchend when in shadow root` , ( ) => {
716+ // Move the field into shadow root to verify the deep active element logic
717+ const inner = document . createElement ( 'div' ) ;
718+ inner . attachShadow ( { mode : 'open' } ) ;
719+ container . appendChild ( inner ) ;
720+ inner . shadowRoot . appendChild ( fields [ 1 ] ) ;
721+
722+ const input = fields [ 1 ] . inputElement ;
723+ input . focus ( ) ;
724+
725+ const e = new CustomEvent ( 'touchend' , { cancelable : true } ) ;
726+ button . dispatchEvent ( e ) ;
727+
728+ expect ( inner . shadowRoot . activeElement ) . to . be . equal ( input ) ;
729+ } ) ;
730+ } ) ;
731+ } ) ;
732+ } ) ;
0 commit comments