Standardize event names to be consistent with @headlessui-react

Was previously using Vue names since Vue was the primary reference while porting, but as the public API is closer to the React one it makes sense to use that.

Fixes #8
This commit is contained in:
Ryan Gossiaux
2021-12-19 00:28:09 -08:00
parent 63d44e125c
commit 8e890b2e80
9 changed files with 13 additions and 18 deletions

View File

@@ -164,7 +164,7 @@
}, },
select(value: unknown) { select(value: unknown) {
if (disabled) return; if (disabled) return;
dispatch("updateValue", { value }); dispatch("change", value);
}, },
}); });
setContext(LISTBOX_CONTEXT_NAME, api); setContext(LISTBOX_CONTEXT_NAME, api);

View File

@@ -70,7 +70,7 @@
(option) => option.propsRef.value === nextValue (option) => option.propsRef.value === nextValue
)?.propsRef; )?.propsRef;
if (nextOption?.disabled) return false; if (nextOption?.disabled) return false;
dispatch("updateValue", nextValue); dispatch("change", nextValue);
return true; return true;
}, },
registerOption(action: Option) { registerOption(action: Option) {

View File

@@ -18,7 +18,7 @@
$: switchStore = $api?.switchStore; $: switchStore = $api?.switchStore;
function toggle() { function toggle() {
dispatch("updateValue", !checked); dispatch("change", !checked);
} }
function handleClick(event: MouseEvent) { function handleClick(event: MouseEvent) {

View File

@@ -61,7 +61,7 @@
setSelectedIndex(index: number) { setSelectedIndex(index: number) {
if (selectedIndex === index) return; if (selectedIndex === index) return;
selectedIndex = index; selectedIndex = index;
dispatch("updateValue", index); dispatch("change", index);
}, },
registerTab(tab: typeof tabs[number]) { registerTab(tab: typeof tabs[number]) {
if (!tabs.includes(tab)) tabs = [...tabs, tab]; if (!tabs.includes(tab)) tabs = [...tabs, tab];

View File

@@ -36,9 +36,9 @@
<div class="space-y-1"> <div class="space-y-1">
<Listbox <Listbox
value={active} value={active}
on:updateValue={(event) => { on:change={(event) => {
console.log("value:", event.detail.value); console.log("value:", event.detail);
active = event.detail.value; active = event.detail;
}} }}
> >
<ListboxLabel class="block text-sm font-medium leading-5 text-gray-700"> <ListboxLabel class="block text-sm font-medium leading-5 text-gray-700">

View File

@@ -7,8 +7,6 @@
ListboxOptions, ListboxOptions,
} from "$lib"; } from "$lib";
import { onMount } from "svelte";
function classNames( function classNames(
...classes: (false | null | undefined | string)[] ...classes: (false | null | undefined | string)[]
): string { ): string {
@@ -36,8 +34,8 @@
<div class="space-y-1"> <div class="space-y-1">
<Listbox <Listbox
value={active} value={active}
on:updateValue={(event) => { on:change={(event) => {
active = event.detail.value; active = event.detail;
}} }}
> >
<ListboxLabel class="block text-sm font-medium leading-5 text-gray-700"> <ListboxLabel class="block text-sm font-medium leading-5 text-gray-700">

View File

@@ -20,15 +20,12 @@
description: "You are the only one able to access this project", description: "You are the only one able to access this project",
}, },
]; ];
let active; let active: typeof access[number];
</script> </script>
<div class="p-12 max-w-xl"> <div class="p-12 max-w-xl">
<a href="/">Link before</a> <a href="/">Link before</a>
<RadioGroup <RadioGroup value={active} on:change={(event) => (active = event.detail)}>
value={active}
on:updateValue={(event) => (active = event.detail)}
>
<fieldset class="space-y-4"> <fieldset class="space-y-4">
<legend> <legend>
<h2 class="text-xl">Privacy setting</h2> <h2 class="text-xl">Privacy setting</h2>

View File

@@ -15,7 +15,7 @@
<Switch <Switch
as="button" as="button"
checked={state} checked={state}
on:updateValue={(event) => (state = event.detail)} on:change={(event) => (state = event.detail)}
class={({ checked }) => class={({ checked }) =>
classNames( classNames(
"relative inline-flex flex-shrink-0 h-6 border-2 border-transparent rounded-full cursor-pointer w-11 focus:outline-none focus:shadow-outline transition-colors ease-in-out duration-200", "relative inline-flex flex-shrink-0 h-6 border-2 border-transparent rounded-full cursor-pointer w-11 focus:outline-none focus:shadow-outline transition-colors ease-in-out duration-200",

View File

@@ -33,7 +33,7 @@
<Switch <Switch
as="button" as="button"
checked={manual} checked={manual}
on:updateValue={(event) => (manual = event.detail)} on:change={(event) => (manual = event.detail)}
class={({ checked }) => class={({ checked }) =>
classNames( classNames(
"relative inline-flex flex-shrink-0 h-6 border-2 border-transparent rounded-full cursor-pointer w-11 focus:outline-none focus:shadow-outline transition-colors ease-in-out duration-200", "relative inline-flex flex-shrink-0 h-6 border-2 border-transparent rounded-full cursor-pointer w-11 focus:outline-none focus:shadow-outline transition-colors ease-in-out duration-200",