File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change 1
1
/* @flow strict */
2
2
3
+ import { scrollTo } from './scroll'
4
+
3
5
export function install ( input : HTMLTextAreaElement | HTMLInputElement , list : HTMLElement ) : void {
4
6
input . addEventListener ( 'compositionstart' , trackComposition )
5
7
input . addEventListener ( 'compositionend' , trackComposition )
@@ -103,6 +105,7 @@ export function navigate(
103
105
if ( target === el ) {
104
106
input . setAttribute ( 'aria-activedescendant' , target . id )
105
107
target . setAttribute ( 'aria-selected' , 'true' )
108
+ scrollTo ( list , target )
106
109
} else {
107
110
el . setAttribute ( 'aria-selected' , 'false' )
108
111
}
Original file line number Diff line number Diff line change
1
+ /* @flow strict */
2
+
3
+ export function scrollTo ( container : HTMLElement , target : HTMLElement ) {
4
+ if ( ! inViewport ( container , target ) ) {
5
+ container . scrollTop = target . offsetTop
6
+ }
7
+ }
8
+
9
+ function inViewport ( container : HTMLElement , element : HTMLElement ) : boolean {
10
+ const scrollTop = container . scrollTop
11
+ const containerBottom = scrollTop + container . clientHeight
12
+ const top = element . offsetTop
13
+ const bottom = top + element . clientHeight
14
+ return top >= scrollTop && bottom <= containerBottom
15
+ }
You can’t perform that action at this time.
0 commit comments