Skip to content

Commit

Permalink
refactor: focusability on dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
mwargan committed Mar 16, 2024
1 parent 4567492 commit 4108cd8
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/components/DropdownSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,19 @@ const getSummaryText = () => {
return props.placeholder;
};
const canBeFocusedOn = computed(
() =>
(props.isOpen &&
searchInput.value &&
props.searchable &&
props.autofocus) ??
false
);
watch(
() => props.isOpen,
() => {
if (!props.isOpen) return;
if (!props.searchable) return;
if (!searchInput.value) return;
if (!props.autofocus) return;
if (!canBeFocusedOn.value) return;
searchInput.value?.focus();
// Scroll the dropdown to the top - this is needed because the CSS height animation seems to leave us a little bit scrolled down
if (dropdownList.value) {
Expand Down Expand Up @@ -314,7 +320,7 @@ watch(
:aria-busy="props.ariaBusy"
:placeholder="props.searchPlaceholder"
:aria-label="props.searchPlaceholder"
autofocus
:autofocus="canBeFocusedOn"
ref="searchInput"
/>
</li>
Expand Down

0 comments on commit 4108cd8

Please sign in to comment.