Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call custom event handlers #3073

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dirty-fans-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@skeletonlabs/skeleton-svelte': patch
---

bugfix: Call custom event handlers provided in ZagJs's internal handlers
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
accordion.machine({
id: useId(),
onValueChange(details) {
zagProps.onValueChange?.(details);
value = details.value;
}
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,19 @@
collection,
value: $state.snapshot(value),
loopFocus: true,
onOpenChange() {
onOpenChange(details) {
zagProps.onOpenChange?.(details);
options = data;
},
onInputValueChange({ inputValue }) {
const filtered = data.filter((item) => item.label.toLowerCase().includes(inputValue.toLowerCase()));
onInputValueChange(details) {
zagProps.onInputValueChange?.(details);
const filtered = data.filter((item) => item.label.toLowerCase().includes(details.inputValue.toLowerCase()));
const newOptions = filtered.length > 0 ? filtered : data;
collection.setItems(newOptions);
options = newOptions;
},
onValueChange(event) {
zagProps.onValueChange?.(event);
value = event.value;
}
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@
id: useId(),
count: data.length,
onPageChange(details) {
zagProps.onPageChange?.(details);
page = details.page;
},
onPageSizeChange(details) {
zagProps.onPageSizeChange?.(details);
pageSize = details.pageSize;
}
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
id: useId(),
open,
onOpenChange(details) {
zagProps.onOpenChange?.(details);
open = details.open;
}
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import { useId } from '$lib/internal/use-id.js';
import { starEmpty, starHalf, starFull } from '$lib/internal/snippets.js';
import type { RatingProps } from './types.js';
import { noop } from '$lib/internal/noop.js';

// Props
let {
Expand Down Expand Up @@ -32,8 +31,6 @@
iconFull = starFull,
// Children
label,
// Events
onValueChange = noop,
// Zag
...zagProps
}: RatingProps = $props();
Expand All @@ -43,8 +40,8 @@
rating.machine({
id: useId(),
onValueChange: (details) => {
zagProps.onValueChange?.(details);
value = details.value;
onValueChange(details.value);
}
}),
{
Expand Down
6 changes: 1 addition & 5 deletions packages/skeleton-svelte/src/lib/components/Rating/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as rating from '@zag-js/rating-group';
import type { Snippet } from 'svelte';

export interface RatingProps extends Omit<rating.Context, 'id' | 'onValueChange'> {
export interface RatingProps extends Omit<rating.Context, 'id'> {
// Root ---
/** Set root base classes */
base?: string;
Expand Down Expand Up @@ -47,8 +47,4 @@ export interface RatingProps extends Omit<rating.Context, 'id' | 'onValueChange'
iconFull?: Snippet;
/** Set the label snippet */
label?: Snippet;

// Events ---
/** Set the onValueChange callback */
onValueChange?: (value: number) => void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
radio.machine({
id: useId(),
onValueChange(details) {
zagProps.onValueChange?.(details);
value = details.value;
},
orientation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface SegmentContext {

// Components ---

export interface SegmentProps extends Omit<radio.Context, 'id' | 'orientation' | 'onValueChange'> {
export interface SegmentProps extends Omit<radio.Context, 'id' | 'orientation'> {
/** Set the active value. */
value?: string;
/** Set the orientation. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
slider.machine({
id: useId(),
onValueChange(details) {
zagProps.onValueChange?.(details);
value = details.value;
}
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
tabs.machine({
id: useId(),
onValueChange(details) {
zagProps.onValueChange?.(details);
value = details.value;
}
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/skeleton-svelte/src/lib/components/Tabs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface TabsContextState {

// Components ---

export interface TabsProps extends Omit<tabs.Context, 'id' | 'orientation' | 'onValueChange'> {
export interface TabsProps extends Omit<tabs.Context, 'id' | 'orientation'> {
/** Set the active value. */
value?: string;
/** Set tabs to stretch to fill the available width. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
tagsInput.machine({
id: useId(),
onValueChange: (details) => {
zagProps.onValueChange?.(details);
value = details.value;
}
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
id: useId(),
open,
onOpenChange(details) {
zagProps.onOpenChange?.(details);
open = details.open;
}
}),
Expand Down
Loading