From d8126eea166b3dd0fd3985c48d878f50b684d65e Mon Sep 17 00:00:00 2001 From: Benjamin French Date: Thu, 27 Jun 2019 13:17:32 +0200 Subject: [PATCH] Removed the select function in Autocomplete, because it is not used anymore. scroll.js was also removed as it was only used in the select function. --- src/autocomplete.js | 10 ---------- src/scroll.js | 15 --------------- 2 files changed, 25 deletions(-) delete mode 100644 src/scroll.js diff --git a/src/autocomplete.js b/src/autocomplete.js index bda25e8..35f5122 100644 --- a/src/autocomplete.js +++ b/src/autocomplete.js @@ -3,7 +3,6 @@ import type AutocompleteElement from './auto-complete-element' import debounce from './debounce' import {fragment} from './send' -import {scrollTo} from './scroll' import {install as installCombobox, uninstall as uninstallCombobox} from '@github/combobox-nav' export default class Autocomplete { @@ -64,15 +63,6 @@ export default class Autocomplete { return sibling || def } - select(target: HTMLElement) { - for (const el of this.results.querySelectorAll('[aria-selected="true"]')) { - el.removeAttribute('aria-selected') - } - target.setAttribute('aria-selected', 'true') - this.input.setAttribute('aria-activedescendant', target.id) - scrollTo(this.results, target) - } - onKeydown(event: KeyboardEvent) { if (event.key === 'Escape' && this.container.open) { this.container.open = false diff --git a/src/scroll.js b/src/scroll.js deleted file mode 100644 index 5b741a8..0000000 --- a/src/scroll.js +++ /dev/null @@ -1,15 +0,0 @@ -/* @flow strict */ - -export function scrollTo(container: HTMLElement, target: HTMLElement) { - if (!inViewport(container, target)) { - container.scrollTop = target.offsetTop - } -} - -function inViewport(container: HTMLElement, element: HTMLElement): boolean { - const scrollTop = container.scrollTop - const containerBottom = scrollTop + container.clientHeight - const top = element.offsetTop - const bottom = top + element.clientHeight - return top >= scrollTop && bottom <= containerBottom -}