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 {
85
85
)
86
86
}
87
87
88
+ function visible ( el ) : boolean {
89
+ return ! el . hidden && ( ! el . type || el . type !== 'hidden' ) && ( el . offsetWidth > 0 || el . offsetHeight > 0 )
90
+ }
91
+
88
92
export function navigate (
89
93
input : HTMLTextAreaElement | HTMLInputElement ,
90
94
list : HTMLElement ,
91
95
indexDiff : - 1 | 1 = 1
92
96
) : 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 )
95
99
const focusIndex = els . indexOf ( focusEl )
96
100
let indexOfItem = indexDiff === 1 ? 0 : els . length - 1
97
101
if ( focusEl && focusIndex >= 0 ) {
Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ describe('combobox-nav', function() {
50
50
<li><del>BB-8</del></li>
51
51
<li id="hubot" role="option">Hubot</li>
52
52
<li id="r2-d2" role="option">R2-D2</li>
53
+ <li id="johnny-5" hidden role="option">Johnny 5</li>
53
54
<li id="wall-e" role="option" aria-disabled="true">Wall-E</li>
54
55
<li><a href="#wall-e" role="option">Wall-E</a></li>
55
56
</ul>
@@ -86,10 +87,10 @@ describe('combobox-nav', function() {
86
87
assert . equal ( input . getAttribute ( 'aria-activedescendant' ) , 'r2-d2' )
87
88
88
89
press ( input , 'ArrowDown' )
89
- assert . equal ( options [ 4 ] . getAttribute ( 'aria-selected' ) , 'true' )
90
+ assert . equal ( options [ 5 ] . getAttribute ( 'aria-selected' ) , 'true' )
90
91
assert . equal ( input . getAttribute ( 'aria-activedescendant' ) , 'wall-e' )
91
92
press ( input , 'Enter' )
92
- click ( options [ 4 ] )
93
+ click ( options [ 5 ] )
93
94
94
95
press ( input , 'ArrowUp' )
95
96
assert . equal ( options [ 3 ] . getAttribute ( 'aria-selected' ) , 'true' )
@@ -128,7 +129,7 @@ describe('combobox-nav', function() {
128
129
eventFired = true
129
130
} )
130
131
131
- click ( document . querySelectorAll ( '[role=option]' ) [ 4 ] )
132
+ click ( document . querySelectorAll ( '[role=option]' ) [ 5 ] )
132
133
assert ( eventFired )
133
134
assert . equal ( window . location . hash , '#wall-e' )
134
135
} )
You can’t perform that action at this time.
0 commit comments