@@ -96,32 +96,33 @@ function attachOneDropdownAria($dropdown) {
9696}
9797
9898function attachOneDropdownAriaTemplated ( $dropdown ) {
99- window . console && console . log ( '[attachOneDropdownAriaTemplated] ' + $dropdown . prop ( 'id' ) ) ;
10099 if ( $dropdown . attr ( 'data-aria-attached' ) ) return ;
101100 $dropdown . attr ( 'data-aria-attached' , 1 ) ;
102101
103102 const $menu = $dropdown . find ( '> .menu' ) ;
104103 // update aria attributes according to current active/selected item
105104 const refreshAria = ( ) => {
106105 const isMenuVisible = ! $menu . is ( '.hidden' ) && ! $menu . is ( '.animating.out' ) ;
107- isMenuVisible ? $dropdown . attr ( 'aria-expanded' , 'true' ) : $dropdown . removeAttr ( 'aria-expanded' ) ;
106+ if ( isMenuVisible ) {
107+ $dropdown . attr ( 'aria-expanded' , 'true' ) ;
108+ } else {
109+ $dropdown . removeAttr ( 'aria-expanded' ) ;
110+ }
108111
109112 let $active = $menu . find ( '> .item.active' ) ;
110- // if (!$active.length) $active = $menu.find('> .item.selected'); // it's strange that we need this fallback at the moment
113+ if ( ! $active . length ) $active = $menu . find ( '> .item.selected' ) ; // it's strange that we need this fallback at the moment
111114
112115 // if there is an active item, use its id. if no active item, then the empty string is set
113116 $dropdown . attr ( 'aria-activedescendant' , $active . attr ( 'id' ) ) ;
114117 } ;
115118
116119 $dropdown . on ( 'keydown' , ( e ) => {
117- window . console && console . log ( 'keydown:' + e . key ) ;
118120 // here it must use keydown event before dropdown's keyup handler, otherwise there is no Enter event in our keyup handler
119121 if ( e . key === 'Enter' ) {
120122 const $item = $dropdown . dropdown ( 'get item' , $dropdown . dropdown ( 'get value' ) ) ;
121123 // if the selected item is clickable, then trigger the click event. in the future there could be a special CSS class for it.
122124 if ( $item ) $item [ 0 ] . click ( ) ;
123- }
124- else if ( e . key === 'ESC' ) {
125+ } else if ( e . key === 'ESC' ) {
125126 $dropdown . dropdown ( 'hide' ) ;
126127 $dropdown . removeAttr ( 'aria-expanded' ) ;
127128 }
0 commit comments