From 12f6515710ef16d32255014cbe07909d2e8f1b0e Mon Sep 17 00:00:00 2001 From: MinamiFunakoshiTR Date: Mon, 31 Mar 2025 15:09:02 -0700 Subject: [PATCH] adds onsearch --- src/components/SearchInput/SearchInput.mdx | 18 ++++++++++-------- .../SearchInput/SearchInput.stories.svelte | 15 ++++++++++++++- src/components/SearchInput/SearchInput.svelte | 14 ++++++++++++-- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/components/SearchInput/SearchInput.mdx b/src/components/SearchInput/SearchInput.mdx index cd743181..6c347cd5 100644 --- a/src/components/SearchInput/SearchInput.mdx +++ b/src/components/SearchInput/SearchInput.mdx @@ -12,16 +12,18 @@ The `SearchInput` component creates a search bar. - + ``` - \ No newline at end of file + diff --git a/src/components/SearchInput/SearchInput.stories.svelte b/src/components/SearchInput/SearchInput.stories.svelte index bca718e7..ae596d55 100644 --- a/src/components/SearchInput/SearchInput.stories.svelte +++ b/src/components/SearchInput/SearchInput.stories.svelte @@ -8,4 +8,17 @@ }); - \ No newline at end of file + + + + + diff --git a/src/components/SearchInput/SearchInput.svelte b/src/components/SearchInput/SearchInput.svelte index c89a83dc..01e78d05 100644 --- a/src/components/SearchInput/SearchInput.svelte +++ b/src/components/SearchInput/SearchInput.svelte @@ -6,15 +6,23 @@ interface Props { /** The placeholder text that appears in the search box.*/ searchPlaceholder?: string; + /** Optional function that runs when the input value changes. */ + onsearch?: (newValue: string) => void; } - let { searchPlaceholder = 'Search...' }: Props = $props(); + let { searchPlaceholder = 'Search...', onsearch }: Props = $props(); let value = $state(''); let active = $derived(value !== ''); function clear() { value = ''; + if (onsearch) onsearch(value); // Call the prop to update the parent when cleared + } + + function oninput(event: Event) { + value = (event.target as HTMLInputElement).value; + if (onsearch) onsearch(value); // Update the parent on every input change } @@ -22,12 +30,14 @@
+
\ No newline at end of file +