Skip to content

Commit

Permalink
Scroll menu items into view when using keyboard (#248)
Browse files Browse the repository at this point in the history
Co-authored-by: Sascha Ißbrücker <sascha.issbruecker@gmail.com>
  • Loading branch information
sissbruecker and sissbruecker authored May 13, 2022
1 parent ca5dcb8 commit dc0a4e3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion bookmarks/components/TagAutocomplete.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
let isFocus = false;
let isOpen = false;
let input = null;
let suggestionList = null;
let suggestions = [];
let selectedIndex = 0;
Expand Down Expand Up @@ -100,6 +101,16 @@
if (newIndex >= length) newIndex = 0;
selectedIndex = newIndex;
// Scroll to selected list item
setTimeout(() => {
if (suggestionList) {
const selectedListItem = suggestionList.querySelector('li.selected');
if (selectedListItem) {
selectedListItem.scrollIntoView({block: 'center'});
}
}
}, 0);
}
</script>

Expand All @@ -114,7 +125,8 @@
</div>

<!-- autocomplete suggestion list -->
<ul class="menu" class:open={isOpen && suggestions.length > 0}>
<ul class="menu" class:open={isOpen && suggestions.length > 0}
bind:this={suggestionList}>
<!-- menu list items -->
{#each suggestions as tag,i}
<li class="menu-item" class:selected={selectedIndex === i}>
Expand Down

0 comments on commit dc0a4e3

Please sign in to comment.