File tree Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -85,13 +85,17 @@ function fireCommitEvent(target: Element): void {
8585 )
8686}
8787
88+ function visible ( el ) : boolean {
89+ return ! el . hidden && ( ! el . type || el . type !== 'hidden' ) && ( el . offsetWidth > 0 || el . offsetHeight > 0 )
90+ }
91+
8892export function navigate (
8993 input : HTMLTextAreaElement | HTMLInputElement ,
9094 list : HTMLElement ,
9195 indexDiff : - 1 | 1 = 1
9296) : void {
93- const focusEl = list . querySelector ( '[aria-selected="true"]' )
94- const els = Array . from ( list . querySelectorAll ( '[role="option"]' ) )
97+ const focusEl = Array . from ( list . querySelectorAll ( '[aria-selected="true"]' ) ) . filter ( visible ) [ 0 ]
98+ const els = Array . from ( list . querySelectorAll ( '[role="option"]' ) ) . filter ( visible )
9599 const focusIndex = els . indexOf ( focusEl )
96100 let indexOfItem = indexDiff === 1 ? 0 : els . length - 1
97101 if ( focusEl && focusIndex >= 0 ) {
Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ describe('combobox-nav', function() {
5050 <li><del>BB-8</del></li>
5151 <li id="hubot" role="option">Hubot</li>
5252 <li id="r2-d2" role="option">R2-D2</li>
53+ <li id="johnny-5" hidden role="option">Johnny 5</li>
5354 <li id="wall-e" role="option" aria-disabled="true">Wall-E</li>
5455 <li><a href="#wall-e" role="option">Wall-E</a></li>
5556 </ul>
@@ -86,10 +87,10 @@ describe('combobox-nav', function() {
8687 assert . equal ( input . getAttribute ( 'aria-activedescendant' ) , 'r2-d2' )
8788
8889 press ( input , 'ArrowDown' )
89- assert . equal ( options [ 4 ] . getAttribute ( 'aria-selected' ) , 'true' )
90+ assert . equal ( options [ 5 ] . getAttribute ( 'aria-selected' ) , 'true' )
9091 assert . equal ( input . getAttribute ( 'aria-activedescendant' ) , 'wall-e' )
9192 press ( input , 'Enter' )
92- click ( options [ 4 ] )
93+ click ( options [ 5 ] )
9394
9495 press ( input , 'ArrowUp' )
9596 assert . equal ( options [ 3 ] . getAttribute ( 'aria-selected' ) , 'true' )
@@ -128,7 +129,7 @@ describe('combobox-nav', function() {
128129 eventFired = true
129130 } )
130131
131- click ( document . querySelectorAll ( '[role=option]' ) [ 4 ] )
132+ click ( document . querySelectorAll ( '[role=option]' ) [ 5 ] )
132133 assert ( eventFired )
133134 assert . equal ( window . location . hash , '#wall-e' )
134135 } )
You can’t perform that action at this time.
0 commit comments