Skip to content

Commit

Permalink
refactor: combobox
Browse files Browse the repository at this point in the history
  • Loading branch information
alextran1502 committed Nov 4, 2024
1 parent 8f7cb4b commit b5de150
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
16 changes: 9 additions & 7 deletions web/src/lib/components/shared-components/combobox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
</script>

<script lang="ts">
import { run } from 'svelte/legacy';
import { fly } from 'svelte/transition';
import Icon from '$lib/components/elements/icon.svelte';
import { mdiMagnify, mdiUnfoldMoreHorizontal, mdiClose } from '@mdi/js';
Expand Down Expand Up @@ -65,9 +63,8 @@
let searchQuery = $state(selectedOption?.label || '');
let selectedIndex: number | undefined = $state();
let optionRefs: HTMLElement[] = $state([]);
let input: HTMLInputElement = $state();
let input = $state<HTMLInputElement>();
let bounds: DOMRect | undefined = $state();
let dropdownDirection: 'bottom' | 'top' = $state('bottom');
const inputId = `combobox-${id}`;
const listboxId = `listbox-${id}`;
Expand All @@ -90,8 +87,11 @@
);
onMount(() => {
if (!input) {
return;
}
observer.observe(input);
const scrollableAncestor = input.closest('.overflow-y-auto, .overflow-y-scroll');
const scrollableAncestor = input?.closest('.overflow-y-auto, .overflow-y-scroll');
scrollableAncestor?.addEventListener('scroll', onPositionChange);
window.visualViewport?.addEventListener('resize', onPositionChange);
window.visualViewport?.addEventListener('scroll', onPositionChange);
Expand Down Expand Up @@ -162,7 +162,6 @@
const calculatePosition = (boundary: DOMRect | undefined) => {
const visualViewport = window.visualViewport;
dropdownDirection = getComboboxDirection(boundary, visualViewport);
if (!boundary) {
return;
Expand Down Expand Up @@ -217,13 +216,16 @@
};
const getInputPosition = () => input?.getBoundingClientRect();
run(() => {
$effect(() => {
searchQuery = selectedOption ? selectedOption.label : '';
});
let filteredOptions = $derived(
options.filter((option) => option.label.toLowerCase().includes(searchQuery.toLowerCase())),
);
let position = $derived(calculatePosition(bounds));
let dropdownDirection: 'bottom' | 'top' = $derived(getComboboxDirection(bounds, visualViewport));

Check failure on line 228 in web/src/lib/components/shared-components/combobox.svelte

View workflow job for this annotation

GitHub Actions / Test & Lint Web

src/lib/components/shared-components/change-date.spec.ts > ChangeDate component > should render correct values

ReferenceError: visualViewport is not defined in {expression} in combobox.svelte in full-screen-modal.svelte in confirm-dialog.svelte in change-date.svelte ❯ src/lib/components/shared-components/combobox.svelte:228:83 ❯ Module.update_reaction node_modules/svelte/src/internal/client/runtime.js:327:56 ❯ execute_derived node_modules/svelte/src/internal/client/reactivity/deriveds.js:120:34 ❯ Module.update_derived node_modules/svelte/src/internal/client/reactivity/deriveds.js:144:14 ❯ Module.get node_modules/svelte/src/internal/client/runtime.js:795:26 ❯ {expression} src/lib/components/shared-components/combobox.svelte:458:116 ❯ update_reaction node_modules/svelte/src/internal/client/runtime.js:327:56 ❯ Module.update_effect node_modules/svelte/src/internal/client/runtime.js:455:18 ❯ create_effect node_modules/svelte/src/internal/client/reactivity/effects.js:98:26 ❯ src/lib/components/shared-components/combobox.svelte:228:83 ❯ {expression} src/lib/components/shared-components/combobox.svelte:458:116

Check failure on line 228 in web/src/lib/components/shared-components/combobox.svelte

View workflow job for this annotation

GitHub Actions / Test & Lint Web

src/lib/components/shared-components/change-date.spec.ts > ChangeDate component > calls onConfirm with correct date on confirm

ReferenceError: visualViewport is not defined in {expression} in combobox.svelte in full-screen-modal.svelte in confirm-dialog.svelte in change-date.svelte ❯ src/lib/components/shared-components/combobox.svelte:228:83 ❯ Module.update_reaction node_modules/svelte/src/internal/client/runtime.js:327:56 ❯ execute_derived node_modules/svelte/src/internal/client/reactivity/deriveds.js:120:34 ❯ Module.update_derived node_modules/svelte/src/internal/client/reactivity/deriveds.js:144:14 ❯ Module.get node_modules/svelte/src/internal/client/runtime.js:795:26 ❯ {expression} src/lib/components/shared-components/combobox.svelte:458:116 ❯ update_reaction node_modules/svelte/src/internal/client/runtime.js:327:56 ❯ Module.update_effect node_modules/svelte/src/internal/client/runtime.js:455:18 ❯ create_effect node_modules/svelte/src/internal/client/reactivity/effects.js:98:26 ❯ src/lib/components/shared-components/combobox.svelte:228:83 ❯ {expression} src/lib/components/shared-components/combobox.svelte:458:116

Check failure on line 228 in web/src/lib/components/shared-components/combobox.svelte

View workflow job for this annotation

GitHub Actions / Test & Lint Web

src/lib/components/shared-components/change-date.spec.ts > ChangeDate component > calls onCancel on cancel

ReferenceError: visualViewport is not defined in {expression} in combobox.svelte in full-screen-modal.svelte in confirm-dialog.svelte in change-date.svelte ❯ src/lib/components/shared-components/combobox.svelte:228:83 ❯ Module.update_reaction node_modules/svelte/src/internal/client/runtime.js:327:56 ❯ execute_derived node_modules/svelte/src/internal/client/reactivity/deriveds.js:120:34 ❯ Module.update_derived node_modules/svelte/src/internal/client/reactivity/deriveds.js:144:14 ❯ Module.get node_modules/svelte/src/internal/client/runtime.js:795:26 ❯ {expression} src/lib/components/shared-components/combobox.svelte:458:116 ❯ update_reaction node_modules/svelte/src/internal/client/runtime.js:327:56 ❯ Module.update_effect node_modules/svelte/src/internal/client/runtime.js:455:18 ❯ create_effect node_modules/svelte/src/internal/client/reactivity/effects.js:98:26 ❯ src/lib/components/shared-components/combobox.svelte:228:83 ❯ {expression} src/lib/components/shared-components/combobox.svelte:458:116

Check failure on line 228 in web/src/lib/components/shared-components/combobox.svelte

View workflow job for this annotation

GitHub Actions / Test & Lint Web

src/lib/components/shared-components/change-date.spec.ts > ChangeDate component > when date is in daylight saving time > should render correct timezone with offset

ReferenceError: visualViewport is not defined in {expression} in combobox.svelte in full-screen-modal.svelte in confirm-dialog.svelte in change-date.svelte ❯ src/lib/components/shared-components/combobox.svelte:228:83 ❯ Module.update_reaction node_modules/svelte/src/internal/client/runtime.js:327:56 ❯ execute_derived node_modules/svelte/src/internal/client/reactivity/deriveds.js:120:34 ❯ Module.update_derived node_modules/svelte/src/internal/client/reactivity/deriveds.js:144:14 ❯ Module.get node_modules/svelte/src/internal/client/runtime.js:795:26 ❯ {expression} src/lib/components/shared-components/combobox.svelte:458:116 ❯ update_reaction node_modules/svelte/src/internal/client/runtime.js:327:56 ❯ Module.update_effect node_modules/svelte/src/internal/client/runtime.js:455:18 ❯ create_effect node_modules/svelte/src/internal/client/reactivity/effects.js:98:26 ❯ src/lib/components/shared-components/combobox.svelte:228:83 ❯ {expression} src/lib/components/shared-components/combobox.svelte:458:116
</script>

<svelte:window onresize={onPositionChange} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<!-- @migration-task Error while migrating Svelte code: `$:` is not allowed in runes mode, use `$derived` or `$effect` instead -->
<script lang="ts">
import { run } from 'svelte/legacy';
import { afterNavigate, goto } from '$app/navigation';
import { page } from '$app/stores';
import CircleIconButton from '$lib/components/elements/buttons/circle-icon-button.svelte';
Expand Down

0 comments on commit b5de150

Please sign in to comment.