( menuEl: HTMLElement, focusedEl: HTMLElement )
| 262 | // ------------------------------ |
| 263 | |
| 264 | export function scrollIntoView( |
| 265 | menuEl: HTMLElement, |
| 266 | focusedEl: HTMLElement |
| 267 | ): void { |
| 268 | const menuRect = menuEl.getBoundingClientRect(); |
| 269 | const focusedRect = focusedEl.getBoundingClientRect(); |
| 270 | const overScroll = focusedEl.offsetHeight / 3; |
| 271 | |
| 272 | if (focusedRect.bottom + overScroll > menuRect.bottom) { |
| 273 | scrollTo( |
| 274 | menuEl, |
| 275 | Math.min( |
| 276 | focusedEl.offsetTop + |
| 277 | focusedEl.clientHeight - |
| 278 | menuEl.offsetHeight + |
| 279 | overScroll, |
| 280 | menuEl.scrollHeight |
| 281 | ) |
| 282 | ); |
| 283 | } else if (focusedRect.top - overScroll < menuRect.top) { |
| 284 | scrollTo(menuEl, Math.max(focusedEl.offsetTop - overScroll, 0)); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | // ============================== |
| 289 | // Get bounding client object |
no test coverage detected
searching dependent graphs…