- containerKeyDown(event) {
- if (event.key === 'Enter') event.preventDefault();
- if (this.list.classList.contains('hidden')) return;
-
- // Down arrow
- if (event.key === 'ArrowDown') {
- this.moveFocus(true);
- event.preventDefault();
- }
- // Up Arrow
- else if (event.key === 'ArrowUp') {
- this.moveFocus(false);
- event.preventDefault();
- }
- // Escape key
- else if (event.key === 'Escape') {
- this.hideSuggestions();
- event.preventDefault();
- }
- }
-
- moveFocus(forward = true) {
- const focusables = Array.from(this.container.querySelectorAll('input,button'));
- const index = focusables.indexOf(document.activeElement);
- const newFocus = focusables[index + (forward ? 1 : -1)];
- if (newFocus) {
- newFocus.focus()
- }
- }
-