File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed
Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,21 @@ class MenuBarButton extends Button {
3838 this . __triggeredWithActiveKeys = null ;
3939 }
4040
41+ /**
42+ * Override to preserve the `active` attribute while the button's
43+ * sub-menu is expanded, so that the pressed visual state remains.
44+ *
45+ * @param {boolean } active
46+ * @protected
47+ * @override
48+ */
49+ _setActive ( active ) {
50+ if ( ! active && this . hasAttribute ( 'expanded' ) ) {
51+ return ;
52+ }
53+ super . _setActive ( active ) ;
54+ }
55+
4156 /**
4257 * Override method inherited from `ButtonMixin` to allow keyboard navigation with
4358 * arrow keys in the menu bar when the button is focusable in the disabled state.
Original file line number Diff line number Diff line change @@ -473,6 +473,39 @@ describe('sub-menu', () => {
473473 expect ( buttons [ 0 ] . hasAttribute ( 'expanded' ) ) . to . be . false ;
474474 } ) ;
475475 } ) ;
476+
477+ describe ( 'active attribute' , ( ) => {
478+ it ( 'should preserve active attribute on button while sub-menu is open on Enter' , async ( ) => {
479+ enter ( buttons [ 0 ] ) ;
480+ await nextRender ( ) ;
481+ expect ( subMenu . opened ) . to . be . true ;
482+ expect ( buttons [ 0 ] . hasAttribute ( 'active' ) ) . to . be . true ;
483+ } ) ;
484+
485+ it ( 'should preserve active attribute on button while sub-menu is open on Space' , async ( ) => {
486+ space ( buttons [ 0 ] ) ;
487+ await nextRender ( ) ;
488+ expect ( subMenu . opened ) . to . be . true ;
489+ expect ( buttons [ 0 ] . hasAttribute ( 'active' ) ) . to . be . true ;
490+ } ) ;
491+
492+ it ( 'should preserve active attribute on button while sub-menu is open on click' , async ( ) => {
493+ buttons [ 0 ] . click ( ) ;
494+ await nextRender ( ) ;
495+ expect ( subMenu . opened ) . to . be . true ;
496+ expect ( buttons [ 0 ] . hasAttribute ( 'active' ) ) . to . be . true ;
497+ } ) ;
498+
499+ it ( 'should remove active attribute when sub-menu is closed' , async ( ) => {
500+ buttons [ 0 ] . click ( ) ;
501+ await nextRender ( ) ;
502+ expect ( buttons [ 0 ] . hasAttribute ( 'active' ) ) . to . be . true ;
503+
504+ buttons [ 0 ] . click ( ) ;
505+ await nextRender ( ) ;
506+ expect ( buttons [ 0 ] . hasAttribute ( 'active' ) ) . to . be . false ;
507+ } ) ;
508+ } ) ;
476509} ) ;
477510
478511describe ( 'open on hover' , ( ) => {
You can’t perform that action at this time.
0 commit comments