Skip to content

Commit

Permalink
add hover text and for keyboard input fallback to includes(searchText…
Browse files Browse the repository at this point in the history
…) when startsWith is false
  • Loading branch information
joshuaboud committed May 29, 2024
1 parent 11e1971 commit 3cb9cb0
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions houston-common-ui/lib/components/SelectMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
export type SelectMenuOption<T> = {
label: string;
value: T;
hoverText?: string;
};
</script>

Expand Down Expand Up @@ -68,13 +69,18 @@ const { inputBuffer, onInput } = useTempInputBuffer(1000);
const optionRefs = ref<HTMLButtonElement[]>([]);
watchEffect(() => {
const searchText = inputBuffer.value;
const searchText = inputBuffer.value?.toLowerCase();
if (searchText === undefined) {
return;
}
const focusIndex = props.options.findIndex((o) =>
o.label.startsWith(searchText)
let focusIndex = props.options.findIndex((o) =>
o.label.toLowerCase().startsWith(searchText)
);
if (focusIndex === -1) {
focusIndex = props.options.findIndex((o) =>
o.label.toLowerCase().includes(searchText)
);
}
if (focusIndex === -1) {
return;
}
Expand Down Expand Up @@ -130,6 +136,7 @@ watchEffect(() => {
:class="{ 'font-bold': index === currentSelectionIndex }"
class="px-3 text-left hover:bg-accent whitespace-nowrap"
ref="optionRefs"
:title="option.hoverText ?? option.label"
>
{{ option.label }}
</button>
Expand Down

0 comments on commit 3cb9cb0

Please sign in to comment.