diff --git a/components/Input/__test__/__snapshots__/input.spec.ts.snap b/components/Input/__test__/__snapshots__/input.spec.ts.snap index b6d8ca25..8da91f59 100644 --- a/components/Input/__test__/__snapshots__/input.spec.ts.snap +++ b/components/Input/__test__/__snapshots__/input.spec.ts.snap @@ -1,15 +1,15 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`Test: KInput > props: attrs 1`] = `"
"`; +exports[`Test: KInput > props: attrs 1`] = `"
"`; -exports[`Test: KInput > props: cls 1`] = `"
"`; +exports[`Test: KInput > props: cls 1`] = `"
"`; -exports[`Test: KInput > props: disabled 1`] = `"
"`; +exports[`Test: KInput > props: disabled 1`] = `"
"`; -exports[`Test: KInput > props: iconPrefix 1`] = `"
"`; +exports[`Test: KInput > props: iconPrefix 1`] = `"
"`; -exports[`Test: KInput > props: iconSuffix 1`] = `"
"`; +exports[`Test: KInput > props: iconSuffix 1`] = `"
"`; -exports[`Test: KInput > props: placeholder 1`] = `"
"`; +exports[`Test: KInput > props: placeholder 1`] = `"
"`; -exports[`Test: KInput > props: value 1`] = `"
"`; +exports[`Test: KInput > props: value 1`] = `"
"`; diff --git a/components/Input/__test__/input.bind.value.update.svelte b/components/Input/__test__/input.bind.value.update.svelte new file mode 100644 index 00000000..68161327 --- /dev/null +++ b/components/Input/__test__/input.bind.value.update.svelte @@ -0,0 +1,8 @@ + + + +{value} diff --git a/components/Input/__test__/input.spec.ts b/components/Input/__test__/input.spec.ts index 58cfedb2..3b58ae1f 100644 --- a/components/Input/__test__/input.spec.ts +++ b/components/Input/__test__/input.spec.ts @@ -1,7 +1,9 @@ import { tick } from 'svelte'; import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'; +import { fireEvent } from '@testing-library/svelte'; import KInput from '../src'; import KInputSlots from './input.slots.svelte'; +import KInputBindValueUpdate from './input.bind.value.update.svelte'; let host: HTMLElement; @@ -257,4 +259,25 @@ describe('Test: KInput', () => { expect(prefixElm).toBeTruthy(); expect(suffixElm).toBeTruthy(); }); + + test('props: bind value be updated in real time', async () => { + const instance = new KInputBindValueUpdate({ + target: host + }); + expect(instance).toBeTruthy(); + + const spanElm = host.querySelector('span'); + expect(spanElm).toBeTruthy(); + expect(spanElm?.textContent).toBe(''); + + const inputElm = host.querySelector('input'); + expect(inputElm).toBeTruthy(); + + await fireEvent.input(inputElm, { target: { value: 'input change' } }); + await tick(); + + expect(inputElm.value).toBe('input change'); + + expect(spanElm?.textContent).toBe('input change'); + }); }); diff --git a/components/Input/src/index.svelte b/components/Input/src/index.svelte index 57decc61..fd4606d7 100644 --- a/components/Input/src/index.svelte +++ b/components/Input/src/index.svelte @@ -1,53 +1,71 @@ -
+
{#if isError} - + {errorMsg} {/if} @@ -57,12 +75,10 @@ {/if} +export type KInputProps = { + value: string; + placeholder: string; + disabled: boolean; + iconPrefix: string; + iconSuffix: string; + isError: boolean; + errorMsg: string; + cls: string; + attrs: Record; +}; diff --git a/play/src/routes/+page.svelte b/play/src/routes/+page.svelte index 099568e0..bfda4e6d 100644 --- a/play/src/routes/+page.svelte +++ b/play/src/routes/+page.svelte @@ -63,29 +63,39 @@ const spinOptions = { show: false, text: 'loading...', - fullScreen: true + fullScreen: true }; - const handleToggleSpin = () => { spinOptions.show = !spinOptions.show; }; - - $: breadcrumbList = [ - { label: 'home', href: '/' }, - { label: 'breadcrumb', href: '' } - ]; - const addBreadcrumb = () => { - breadcrumbList.push({ label: 'test', href: '' }); - breadcrumbList = breadcrumbList; - }; - const delBreadcrumb = () => { - breadcrumbList.pop(); - breadcrumbList = breadcrumbList; - }; + $: breadcrumbList = [ + { label: 'home', href: '/' }, + { label: 'breadcrumb', href: '' } + ]; + const addBreadcrumb = () => { + breadcrumbList.push({ label: 'test', href: '' }); + breadcrumbList = breadcrumbList; + }; + const delBreadcrumb = () => { + breadcrumbList.pop(); + breadcrumbList = breadcrumbList; + }; +
+
KInput
+ { + console.log('on:input =>', inputValue); + }} + > +
+
Breadcrumb
@@ -140,8 +150,6 @@ open()}>KEyeDropper - - KTooltip - trigger @@ -214,4 +222,4 @@ ToggleSpin
- +