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 11/* @flow strict */
22
3+ import { scrollTo } from './scroll'
4+
35export function install ( input : HTMLTextAreaElement | HTMLInputElement , list : HTMLElement ) : void {
46 input . addEventListener ( 'compositionstart' , trackComposition )
57 input . addEventListener ( 'compositionend' , trackComposition )
@@ -103,6 +105,7 @@ export function navigate(
103105 if ( target === el ) {
104106 input . setAttribute ( 'aria-activedescendant' , target . id )
105107 target . setAttribute ( 'aria-selected' , 'true' )
108+ scrollTo ( list , target )
106109 } else {
107110 el . setAttribute ( 'aria-selected' , 'false' )
108111 }
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