@@ -3,6 +3,7 @@ import $ from 'jquery';
33import ArrayStore from 'common/data/array_store' ;
44import fx from 'common/core/animation/fx' ;
55import Button from 'ui/button' ;
6+ import 'ui/check_box' ;
67import Popup from 'ui/popup' ;
78import DropDownMenu from '__internal/ui/toolbar/internal/m_toolbar.menu' ;
89import ToolbarMenuList from '__internal/ui/toolbar/internal/m_toolbar.menu.list' ;
@@ -13,6 +14,7 @@ import config from 'core/config';
1314import { DataSource } from 'common/data/data_source/data_source' ;
1415import { isRenderer } from 'core/utils/type' ;
1516import themes from 'ui/themes' ;
17+ import { shouldSkipOnMobile } from '../../helpers/device.js' ;
1618
1719import 'generic_light.css!' ;
1820
@@ -32,6 +34,8 @@ const DROP_DOWN_MENU_POPUP_CLASS = 'dx-dropdownmenu-popup';
3234const DROP_DOWN_MENU_POPUP_WRAPPER_CLASS = 'dx-dropdownmenu-popup-wrapper' ;
3335const LIST_ITEM_CLASS = 'dx-list-item' ;
3436const SCROLLVIEW_CONTENT_CLASS = 'dx-scrollview-content' ;
37+ const CHECK_BOX_CLASS = 'dx-checkbox' ;
38+ const BUTTON_CLASS = 'dx-button' ;
3539
3640
3741const moduleConfig = {
@@ -595,6 +599,137 @@ QUnit.module('widget sizing render', moduleConfig, () => {
595599
596600 } ) ;
597601
602+ QUnit . module ( 'esc on popup' , {
603+ beforeEach : function ( ) {
604+ this . instance . option ( {
605+ opened : false ,
606+ items : [ { template : ( ) => $ ( '<div>' ) . dxCheckBox ( { value : false } ) } ] ,
607+ } ) ;
608+ } ,
609+ afterEach : function ( ) {
610+ this . instance . option ( 'opened' , false ) ;
611+ }
612+ } , ( ) => {
613+ QUnit . test ( 'esc on popup overlay should close popup' , function ( assert ) {
614+ if ( shouldSkipOnMobile ( assert ) ) {
615+ return ;
616+ }
617+
618+ this . overflowMenu . $button ( ) . focusin ( ) ;
619+ this . keyboard . keyDown ( 'enter' ) ;
620+
621+ const popup = this . overflowMenu . popup ( ) ;
622+ assert . equal ( popup . option ( 'visible' ) , true , 'popup is visible' ) ;
623+
624+ const $popupContent = popup . $overlayContent ( ) ;
625+
626+ keyboardMock ( $popupContent ) . keyDown ( 'esc' ) ;
627+ assert . equal ( popup . option ( 'visible' ) , false , 'esc on popup overlay closed popup' ) ;
628+ } ) ;
629+
630+ QUnit . test ( 'esc on nested items should NOT close popup' , function ( assert ) {
631+ if ( shouldSkipOnMobile ( assert ) ) {
632+ return ;
633+ }
634+
635+ this . overflowMenu . $button ( ) . focusin ( ) ;
636+ this . keyboard . keyDown ( 'enter' ) ;
637+
638+ const popup = this . overflowMenu . popup ( ) ;
639+ assert . equal ( popup . option ( 'visible' ) , true , 'popup is visible' ) ;
640+
641+ const $checkBox = this . overflowMenu . $popupContent ( ) . find ( `.${ CHECK_BOX_CLASS } ` ) . first ( ) ;
642+
643+ keyboardMock ( $checkBox ) . keyDown ( 'esc' ) ;
644+ assert . equal ( popup . option ( 'visible' ) , true , 'esc on nested item did not close popup' ) ;
645+ } ) ;
646+ } ) ;
647+
648+ QUnit . module ( 'space/enter on list item (T1301705)' , {
649+ beforeEach : function ( ) {
650+ this . instance . option ( {
651+ closeOnClick : true ,
652+ opened : false ,
653+ items : [
654+ {
655+ template : ( ) => $ ( '<div>' ) . dxCheckBox ( { value : false } ) ,
656+ widget : 'dxCheckBox' ,
657+ } ,
658+ {
659+ template : ( ) => $ ( '<div>' ) . dxButton ( { text : 'Button' } )
660+ } ,
661+ ]
662+ } ) ;
663+ } ,
664+ afterEach : function ( ) {
665+ this . instance . option ( 'opened' , false ) ;
666+ }
667+ } , ( ) => {
668+ QUnit . test ( 'space on a not dxButton in nested list item should NOT close popup' , function ( assert ) {
669+ if ( shouldSkipOnMobile ( assert ) ) {
670+ return ;
671+ }
672+
673+ this . overflowMenu . $button ( ) . focusin ( ) ;
674+ this . keyboard . keyDown ( 'enter' ) ;
675+
676+ const popup = this . overflowMenu . popup ( ) ;
677+ assert . equal ( popup . option ( 'visible' ) , true , 'popup is visible' ) ;
678+
679+ const $checkBox = this . overflowMenu . $popupContent ( ) . find ( `.${ CHECK_BOX_CLASS } ` ) . first ( ) ;
680+
681+ keyboardMock ( $checkBox ) . keyDown ( 'space' ) ;
682+ assert . equal ( popup . option ( 'visible' ) , true , 'space on a dxCheckBox did not close popup' ) ;
683+ } ) ;
684+
685+ QUnit . test ( 'enter on a not dxButton in nested list item should NOT close popup' , function ( assert ) {
686+ if ( shouldSkipOnMobile ( assert ) ) {
687+ return ;
688+ }
689+
690+ this . overflowMenu . $button ( ) . focusin ( ) ;
691+ this . keyboard . keyDown ( 'enter' ) ;
692+
693+ const popup = this . overflowMenu . popup ( ) ;
694+ assert . equal ( popup . option ( 'visible' ) , true , 'popup is visible' ) ;
695+
696+ const $checkBox = this . overflowMenu . $popupContent ( ) . find ( `.${ CHECK_BOX_CLASS } ` ) . first ( ) ;
697+
698+ keyboardMock ( $checkBox ) . keyDown ( 'enter' ) ;
699+ assert . equal ( popup . option ( 'visible' ) , true , 'enter on a dxCheckBox did not close popup' ) ;
700+ } ) ;
701+
702+ QUnit . test ( 'space on a dxButton in nested list item should close popup' , function ( assert ) {
703+ if ( shouldSkipOnMobile ( assert ) ) {
704+ return ;
705+ }
706+ this . overflowMenu . $button ( ) . focusin ( ) ;
707+ this . keyboard . keyDown ( 'enter' ) ;
708+
709+ const popup = this . overflowMenu . popup ( ) ;
710+ assert . equal ( popup . option ( 'visible' ) , true , 'popup is visible' ) ;
711+
712+ const $button = this . overflowMenu . $popupContent ( ) . find ( `.${ BUTTON_CLASS } ` ) . first ( ) ;
713+ keyboardMock ( $button ) . keyDown ( 'space' ) ;
714+ assert . equal ( popup . option ( 'visible' ) , false , 'space on a dxButton closed popup' ) ;
715+ } ) ;
716+
717+ QUnit . test ( 'enter on a dxButton in nested list item should close popup' , function ( assert ) {
718+ if ( shouldSkipOnMobile ( assert ) ) {
719+ return ;
720+ }
721+ this . overflowMenu . $button ( ) . focusin ( ) ;
722+ this . keyboard . keyDown ( 'enter' ) ;
723+
724+ const popup = this . overflowMenu . popup ( ) ;
725+ assert . equal ( popup . option ( 'visible' ) , true , 'popup is visible' ) ;
726+
727+ const $button = this . overflowMenu . $popupContent ( ) . find ( `.${ BUTTON_CLASS } ` ) . first ( ) ;
728+ keyboardMock ( $button ) . keyDown ( 'enter' ) ;
729+ assert . equal ( popup . option ( 'visible' ) , false , 'enter on a dxButton closed popup' ) ;
730+ } ) ;
731+ } ) ;
732+
598733 QUnit . test ( 'Enter or space press should call onItemClick (T318240)' , function ( assert ) {
599734 let itemClicked = 0 ;
600735
0 commit comments