diff --git a/src/lib/components/listbox/Listbox.svelte b/src/lib/components/listbox/Listbox.svelte index c0f323d..20125a5 100644 --- a/src/lib/components/listbox/Listbox.svelte +++ b/src/lib/components/listbox/Listbox.svelte @@ -32,7 +32,7 @@ clearSearch(): void; registerOption(id: string, dataRef: ListboxOptionDataRef): void; unregisterOption(id: string): void; - select(value: unknown): void; + select(newValue: unknown): void; }; const LISTBOX_CONTEXT_NAME = "headlessui-listbox-context"; @@ -69,7 +69,7 @@ Focus, calculateActiveIndex, } from "$lib/utils/calculate-active-index"; - import { createEventDispatcher, getContext, setContext } from "svelte"; + import { getContext, setContext } from "svelte"; import type { Readable, Writable } from "svelte/store"; import { writable } from "svelte/store"; import { match } from "$lib/utils/match"; @@ -92,13 +92,7 @@ export let value: StateDefinition["value"]; /***** Events *****/ - const forwardEvents = forwardEventsBuilder(get_current_component(), [ - "change", - ]); - - const dispatch = createEventDispatcher<{ - change: any; - }>(); + const forwardEvents = forwardEventsBuilder(get_current_component()); /***** Component *****/ $: orientation = ( @@ -229,9 +223,9 @@ return nextOptions.indexOf(currentActiveOption); })(); }, - select(value: unknown) { + select(newValue: unknown) { if (disabled) return; - dispatch("change", value); + value = newValue; }, }); setContext(LISTBOX_CONTEXT_NAME, api); diff --git a/src/lib/components/listbox/listbox.test.ts b/src/lib/components/listbox/listbox.test.ts index ad4a001..aa1416f 100644 --- a/src/lib/components/listbox/listbox.test.ts +++ b/src/lib/components/listbox/listbox.test.ts @@ -43,7 +43,7 @@ import { import { Transition } from "../transitions"; import TransitionDebug from "$lib/components/disclosure/_TransitionDebug.svelte"; import svelte from "svelte-inline-compile"; -import { writable } from "svelte/store"; +import { get, writable } from "svelte/store"; let mockId = 0; jest.mock('../../hooks/use-id', () => { @@ -88,7 +88,7 @@ describe('safeguards', () => { 'should be possible to render a Listbox without crashing', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -113,7 +113,7 @@ describe('Rendering', () => { 'should render a Listbox using slot props', suppressConsoleLogs(async () => { render(svelte` - + Trigger {#if open} @@ -145,7 +145,7 @@ describe('Rendering', () => { 'should be possible to disable a Listbox', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -185,7 +185,7 @@ describe('Rendering', () => { 'should be possible to render a ListboxLabel using slot props', suppressConsoleLogs(async () => { render(svelte` - + {JSON.stringify({ open, disabled })} Trigger @@ -222,7 +222,7 @@ describe('Rendering', () => { 'should be possible to render a ListboxLabel with slot props and an `as` prop', suppressConsoleLogs(async () => { render(svelte` - + {JSON.stringify({ open, disabled })} Trigger @@ -256,7 +256,7 @@ describe('Rendering', () => { 'should render a ListboxButton with slot props', suppressConsoleLogs(async () => { render(svelte` - + {JSON.stringify({ open, disabled})} Option A @@ -288,7 +288,7 @@ describe('Rendering', () => { 'should be possible to render a ListboxButton using slot props and an `as` prop', suppressConsoleLogs(async () => { render(svelte` - + {JSON.stringify({ open, disabled })} @@ -322,7 +322,7 @@ describe('Rendering', () => { 'should be possible to render a ListboxButton and a ListboxLabel and see them linked together', suppressConsoleLogs(async () => { render(svelte` - + Label Trigger @@ -348,7 +348,7 @@ describe('Rendering', () => { describe('`type` attribute', () => { it('should set the `type` to "button" by default', async () => { render(svelte` - + Trigger `); @@ -358,7 +358,7 @@ describe('Rendering', () => { it('should not set the `type` to "button" if it already contains a `type`', async () => { render(svelte` - + Trigger `); @@ -368,7 +368,7 @@ describe('Rendering', () => { it('should not set the type if the "as" prop is not a "button"', async () => { render(svelte` - + Trigger `); @@ -384,7 +384,7 @@ describe('Rendering', () => { 'should render ListboxOptions with slot props', suppressConsoleLogs(async () => { render(svelte` - + Trigger {JSON.stringify({ open })} @@ -414,7 +414,7 @@ describe('Rendering', () => { it('should be possible to always render the ListboxOptions if we provide it a `static` prop', () => { render(svelte` - + Trigger Option A @@ -430,7 +430,7 @@ describe('Rendering', () => { it('should be possible to use a different render strategy for the ListboxOptions', async () => { render(svelte` - + Trigger Option A @@ -454,7 +454,7 @@ describe('Rendering', () => { 'should render a ListboxOption with slot props', suppressConsoleLogs(async () => { render(svelte` - + Trigger @@ -486,17 +486,17 @@ describe('Rendering', () => { it('should guarantee the listbox option order after a few unmounts', async () => { let showFirst = writable(false); render(svelte` - - Trigger - - {#if $showFirst} - Option A - {/if} - Option B - Option C - - - `) + + Trigger + + {#if $showFirst} + Option A + {/if} + Option B + Option C + + + `) assertListboxButton({ state: ListboxState.InvisibleUnmounted, @@ -545,7 +545,7 @@ describe('Rendering composition', () => { 'should be possible to conditionally render classNames (aka class can be a function?!)', suppressConsoleLogs(async () => { render(svelte` - + Trigger JSON.stringify(bag)}>Option A @@ -614,7 +614,7 @@ describe('Rendering composition', () => { 'should be possible to swap the Listbox option with a button for example', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -646,7 +646,7 @@ describe('Composition', () => { suppressConsoleLogs(async () => { let orderFn = jest.fn() render(svelte` - + Trigger @@ -701,7 +701,7 @@ describe('Keyboard interactions', () => { 'should be possible to open the listbox with Enter', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -747,7 +747,7 @@ describe('Keyboard interactions', () => { 'should not be possible to open the listbox with Enter when the button is disabled', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -782,7 +782,7 @@ describe('Keyboard interactions', () => { 'should be possible to open the listbox with Enter, and focus the selected option', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -827,7 +827,7 @@ describe('Keyboard interactions', () => { 'should be possible to open the listbox with Enter, and focus the selected option (when using the `hidden` render strategy)', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -893,7 +893,7 @@ describe('Keyboard interactions', () => { { id: 'c', name: 'Option C' }, ] render(svelte` - + Trigger Option A @@ -938,7 +938,7 @@ describe('Keyboard interactions', () => { 'should have no active listbox option when there are no listbox options at all', suppressConsoleLogs(async () => { render(svelte` - + Trigger @@ -962,7 +962,7 @@ describe('Keyboard interactions', () => { 'should focus the first non disabled listbox option when opening with Enter', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -995,7 +995,7 @@ describe('Keyboard interactions', () => { 'should focus the first non disabled listbox option when opening with Enter (jump over multiple disabled ones)', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -1028,7 +1028,7 @@ describe('Keyboard interactions', () => { 'should have no active listbox option upon Enter key press, when there are no non-disabled listbox options', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -1058,7 +1058,7 @@ describe('Keyboard interactions', () => { 'should be possible to close the listbox with Enter when there is no active listboxoption', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -1095,10 +1095,9 @@ describe('Keyboard interactions', () => { it( 'should be possible to close the listbox with Enter and choose the active listbox option', suppressConsoleLogs(async () => { - let handleChange = jest.fn() - let value = writable(); + let value = writable(null); render(svelte` - { value.set(e.detail); handleChange(e.detail) } }> + Trigger Option A @@ -1131,9 +1130,8 @@ describe('Keyboard interactions', () => { assertListboxButton({ state: ListboxState.InvisibleUnmounted }) assertListbox({ state: ListboxState.InvisibleUnmounted }) - // Verify we got the change event - expect(handleChange).toHaveBeenCalledTimes(1) - expect(handleChange).toHaveBeenCalledWith('a') + // Verify the value changed + expect(get(value)).toEqual("a"); // Verify the button is focused again assertActiveElement(getListboxButton()) @@ -1152,7 +1150,7 @@ describe('Keyboard interactions', () => { 'should be possible to open the listbox with Space', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -1195,7 +1193,7 @@ describe('Keyboard interactions', () => { 'should not be possible to open the listbox with Space when the button is disabled', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -1230,7 +1228,7 @@ describe('Keyboard interactions', () => { 'should be possible to open the listbox with Space, and focus the selected option', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -1275,7 +1273,7 @@ describe('Keyboard interactions', () => { 'should have no active listbox option when there are no listbox options at all', suppressConsoleLogs(async () => { render(svelte` - + Trigger @@ -1299,7 +1297,7 @@ describe('Keyboard interactions', () => { 'should focus the first non disabled listbox option when opening with Space', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -1332,7 +1330,7 @@ describe('Keyboard interactions', () => { 'should focus the first non disabled listbox option when opening with Space (jump over multiple disabled ones)', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -1365,7 +1363,7 @@ describe('Keyboard interactions', () => { 'should have no active listbox option upon Space key press, when there are no non-disabled listbox options', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -1394,10 +1392,9 @@ describe('Keyboard interactions', () => { it( 'should be possible to close the listbox with Space and choose the active listbox option', suppressConsoleLogs(async () => { - let handleChange = jest.fn() - let value = writable(); + let value = writable(null); render(svelte` - { value.set(e.detail); handleChange(e.detail) } }> + Trigger Option A @@ -1431,9 +1428,8 @@ describe('Keyboard interactions', () => { assertListboxButton({ state: ListboxState.InvisibleUnmounted }) assertListbox({ state: ListboxState.InvisibleUnmounted }) - // Verify we got the change event - expect(handleChange).toHaveBeenCalledTimes(1) - expect(handleChange).toHaveBeenCalledWith('a') + // Verify the value changed + expect(get(value)).toEqual("a"); // Verify the button is focused again assertActiveElement(getListboxButton()) @@ -1452,7 +1448,7 @@ describe('Keyboard interactions', () => { 'should be possible to close an open listbox with Escape', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -1495,7 +1491,7 @@ describe('Keyboard interactions', () => { 'should focus trap when we use Tab', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -1546,7 +1542,7 @@ describe('Keyboard interactions', () => { 'should focus trap when we use Shift+Tab', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -1599,7 +1595,7 @@ describe('Keyboard interactions', () => { 'should be possible to open the listbox with ArrowDown', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -1643,7 +1639,7 @@ describe('Keyboard interactions', () => { 'should not be possible to open the listbox with ArrowDown when the button is disabled', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -1678,7 +1674,7 @@ describe('Keyboard interactions', () => { 'should be possible to open the listbox with ArrowDown, and focus the selected option', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -1723,7 +1719,7 @@ describe('Keyboard interactions', () => { 'should have no active listbox option when there are no listbox options at all', suppressConsoleLogs(async () => { render(svelte` - + Trigger @@ -1747,7 +1743,7 @@ describe('Keyboard interactions', () => { 'should be possible to use ArrowDown to navigate the listbox options', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -1792,7 +1788,7 @@ describe('Keyboard interactions', () => { 'should be possible to use ArrowDown to navigate the listbox options and skip the first disabled one', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -1830,7 +1826,7 @@ describe('Keyboard interactions', () => { 'should be possible to use ArrowDown to navigate the listbox options and jump to the first non-disabled one', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -1866,7 +1862,7 @@ describe('Keyboard interactions', () => { 'should be possible to use ArrowRight to navigate the listbox options', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -1914,7 +1910,7 @@ describe('Keyboard interactions', () => { 'should be possible to open the listbox with ArrowUp and the last option should be active', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -1959,7 +1955,7 @@ describe('Keyboard interactions', () => { 'should not be possible to open the listbox with ArrowUp and the last option should be active when the button is disabled', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -1994,7 +1990,7 @@ describe('Keyboard interactions', () => { 'should be possible to open the listbox with ArrowUp, and focus the selected option', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -2039,7 +2035,7 @@ describe('Keyboard interactions', () => { 'should have no active listbox option when there are no listbox options at all', suppressConsoleLogs(async () => { render(svelte` - + Trigger @@ -2063,7 +2059,7 @@ describe('Keyboard interactions', () => { 'should be possible to use ArrowUp to navigate the listbox options and jump to the first non-disabled one', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -2097,7 +2093,7 @@ describe('Keyboard interactions', () => { 'should not be possible to navigate up or down if there is only a single non-disabled option', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -2139,7 +2135,7 @@ describe('Keyboard interactions', () => { 'should be possible to use ArrowUp to navigate the listbox options', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -2196,7 +2192,7 @@ describe('Keyboard interactions', () => { 'should be possible to use ArrowLeft to navigate the listbox options', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -2254,7 +2250,7 @@ describe('Keyboard interactions', () => { 'should be possible to use the End key to go to the last listbox option', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -2285,7 +2281,7 @@ describe('Keyboard interactions', () => { 'should be possible to use the End key to go to the last non disabled listbox option', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -2317,7 +2313,7 @@ describe('Keyboard interactions', () => { 'should be possible to use the End key to go to the first listbox option if that is the only non-disabled listbox option', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -2346,7 +2342,7 @@ describe('Keyboard interactions', () => { 'should have no active listbox option upon End key press, when there are no non-disabled listbox options', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -2376,7 +2372,7 @@ describe('Keyboard interactions', () => { 'should be possible to use the PageDown key to go to the last listbox option', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -2407,7 +2403,7 @@ describe('Keyboard interactions', () => { 'should be possible to use the PageDown key to go to the last non disabled listbox option', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -2439,7 +2435,7 @@ describe('Keyboard interactions', () => { 'should be possible to use the PageDown key to go to the first listbox option if that is the only non-disabled listbox option', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -2468,7 +2464,7 @@ describe('Keyboard interactions', () => { 'should have no active listbox option upon PageDown key press, when there are no non-disabled listbox options', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -2498,7 +2494,7 @@ describe('Keyboard interactions', () => { 'should be possible to use the Home key to go to the first listbox option', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -2529,7 +2525,7 @@ describe('Keyboard interactions', () => { 'should be possible to use the Home key to go to the first non disabled listbox option', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -2560,7 +2556,7 @@ describe('Keyboard interactions', () => { 'should be possible to use the Home key to go to the last listbox option if that is the only non-disabled listbox option', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -2589,7 +2585,7 @@ describe('Keyboard interactions', () => { 'should have no active listbox option upon Home key press, when there are no non-disabled listbox options', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -2619,7 +2615,7 @@ describe('Keyboard interactions', () => { 'should be possible to use the PageUp key to go to the first listbox option', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -2650,7 +2646,7 @@ describe('Keyboard interactions', () => { 'should be possible to use the PageUp key to go to the first non disabled listbox option', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -2681,7 +2677,7 @@ describe('Keyboard interactions', () => { 'should be possible to use the PageUp key to go to the last listbox option if that is the only non-disabled listbox option', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -2710,7 +2706,7 @@ describe('Keyboard interactions', () => { 'should have no active listbox option upon PageUp key press, when there are no non-disabled listbox options', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -2740,7 +2736,7 @@ describe('Keyboard interactions', () => { 'should be possible to type a full word that has a perfect match', suppressConsoleLogs(async () => { render(svelte` - + Trigger alice @@ -2773,7 +2769,7 @@ describe('Keyboard interactions', () => { 'should be possible to type a partial of a word', suppressConsoleLogs(async () => { render(svelte` - + Trigger alice @@ -2812,7 +2808,7 @@ describe('Keyboard interactions', () => { 'should be possible to type words with spaces', suppressConsoleLogs(async () => { render(svelte` - + Trigger value a @@ -2851,7 +2847,7 @@ describe('Keyboard interactions', () => { 'should not be possible to search for a disabled option', suppressConsoleLogs(async () => { render(svelte` - + Trigger alice @@ -2884,7 +2880,7 @@ describe('Keyboard interactions', () => { 'should be possible to search for a word (case insensitive)', suppressConsoleLogs(async () => { render(svelte` - + Trigger alice @@ -2917,7 +2913,7 @@ describe('Keyboard interactions', () => { 'should be possible to search for the next occurence', suppressConsoleLogs(async () => { render(svelte` - + Trigger alice @@ -2960,7 +2956,7 @@ describe('Mouse interactions', () => { 'should focus the ListboxButton when we click the ListboxLabel', suppressConsoleLogs(async () => { render(svelte` - + Label Trigger @@ -2986,7 +2982,7 @@ describe('Mouse interactions', () => { 'should not focus the ListboxButton when we right click the ListboxLabel', suppressConsoleLogs(async () => { render(svelte` - + Label Trigger @@ -3012,7 +3008,7 @@ describe('Mouse interactions', () => { 'should be possible to open the listbox on click', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -3051,7 +3047,7 @@ describe('Mouse interactions', () => { 'should not be possible to open the listbox on right click', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -3079,7 +3075,7 @@ describe('Mouse interactions', () => { 'should not be possible to open the listbox on click when the button is disabled', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -3111,7 +3107,7 @@ describe('Mouse interactions', () => { 'should be possible to open the listbox on click, and focus the selected option', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -3153,7 +3149,7 @@ describe('Mouse interactions', () => { 'should be possible to close a listbox on click', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -3182,7 +3178,7 @@ describe('Mouse interactions', () => { 'should be a no-op when we click outside of a closed listbox', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -3207,7 +3203,7 @@ describe('Mouse interactions', () => { 'should be possible to click outside of the listbox which should close the listbox', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -3238,7 +3234,7 @@ describe('Mouse interactions', () => { suppressConsoleLogs(async () => { render(svelte`
- + Trigger Option A @@ -3246,7 +3242,7 @@ describe('Mouse interactions', () => { Option C - + Trigger Option A @@ -3280,7 +3276,7 @@ describe('Mouse interactions', () => { 'should be possible to click outside of the listbox which should close the listbox (even if we press the listbox button)', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -3313,7 +3309,7 @@ describe('Mouse interactions', () => { let focusFn = jest.fn() render(svelte`
- + Trigger Option A @@ -3351,7 +3347,7 @@ describe('Mouse interactions', () => { 'should be possible to hover an option and make it active', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -3383,7 +3379,7 @@ describe('Mouse interactions', () => { 'should make a listbox option active when you move the mouse over it', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -3407,7 +3403,7 @@ describe('Mouse interactions', () => { 'should be a no-op when we move the mouse and the listbox option is already active', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -3437,7 +3433,7 @@ describe('Mouse interactions', () => { 'should be a no-op when we move the mouse and the listbox option is disabled', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -3461,7 +3457,7 @@ describe('Mouse interactions', () => { 'should not be possible to hover an option that is disabled', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -3488,7 +3484,7 @@ describe('Mouse interactions', () => { 'should be possible to mouse leave an option and make it inactive', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -3530,7 +3526,7 @@ describe('Mouse interactions', () => { 'should be possible to mouse leave a disabled option and be a no-op', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -3557,10 +3553,9 @@ describe('Mouse interactions', () => { it( 'should be possible to click a listbox option, which closes the listbox', suppressConsoleLogs(async () => { - let handleChange = jest.fn() - let value = writable(); + let value = writable(null); render(svelte` - { value.set(e.detail); handleChange(e.detail) } }> + Trigger Option A @@ -3580,8 +3575,7 @@ describe('Mouse interactions', () => { // We should be able to click the first option await click(options[1]) assertListbox({ state: ListboxState.InvisibleUnmounted }) - expect(handleChange).toHaveBeenCalledTimes(1) - expect(handleChange).toHaveBeenCalledWith('b') + expect(get(value)).toEqual("b"); // Verify the button is focused again assertActiveElement(getListboxButton()) @@ -3597,10 +3591,9 @@ describe('Mouse interactions', () => { it( 'should be possible to click a disabled listbox option, which is a no-op', suppressConsoleLogs(async () => { - let handleChange = jest.fn() - let value = writable(); + let value = writable(null); render(svelte` - { value.set(e.detail); handleChange(e.detail) } }> + Trigger Option A @@ -3622,7 +3615,7 @@ describe('Mouse interactions', () => { await click(options[1]) assertListbox({ state: ListboxState.Visible }) assertActiveElement(getListbox()) - expect(handleChange).toHaveBeenCalledTimes(0) + expect(get(value)).toBeNull(); // Close the listbox await click(getListboxButton()) @@ -3639,7 +3632,7 @@ describe('Mouse interactions', () => { 'should be possible focus a listbox option, so that it becomes active', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A @@ -3669,7 +3662,7 @@ describe('Mouse interactions', () => { 'should not be possible to focus a listbox option which is disabled', suppressConsoleLogs(async () => { render(svelte` - + Trigger Option A diff --git a/src/routes/listbox/_PeopleList.svelte b/src/routes/listbox/_PeopleList.svelte index f117a98..9b4bdab 100644 --- a/src/routes/listbox/_PeopleList.svelte +++ b/src/routes/listbox/_PeopleList.svelte @@ -32,13 +32,7 @@
- { - console.log("value:", event.detail); - active = event.detail; - }} - > + Assigned to diff --git a/src/routes/listbox/listbox-with-pure-tailwind.svelte b/src/routes/listbox/listbox-with-pure-tailwind.svelte index ea2ddd8..7953998 100644 --- a/src/routes/listbox/listbox-with-pure-tailwind.svelte +++ b/src/routes/listbox/listbox-with-pure-tailwind.svelte @@ -32,12 +32,7 @@
- { - active = event.detail; - }} - > + Assigned to