Skip to content
Merged
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
11 changes: 9 additions & 2 deletions packages/svelte-ux/src/lib/components/TextField.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@
? (node) => [autoFocus(node, typeof autofocus === 'object' ? autofocus : undefined)]
: undefined;
export let operators: { label: string; value: string }[] | undefined = undefined;
export let inputEl: HTMLInputElement | null = null;
export let inputEl: HTMLInputElement | HTMLTextAreaElement | null = null;
// this is a workaround because Input only accepts an HTMLInputElement, not a TextAreaElement
const inputHolder = {
set input(value: HTMLInputElement | null) {
inputEl = value;
},
};
export let debounceChange: boolean | number = false;
export let classes: {
root?: string;
Expand Down Expand Up @@ -327,6 +333,7 @@
{disabled}
value={inputValue}
{autocapitalize}
bind:this={inputEl}
on:input={handleInput}
on:focus
on:blur
Expand Down Expand Up @@ -366,7 +373,7 @@
{max}
{step}
{actions}
bind:inputEl
bind:inputEl={inputHolder.input}
on:input={handleInput}
on:focus
on:blur
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import Preview from '$lib/components/Preview.svelte';
import Blockquote from '$docs/Blockquote.svelte';
import Toggle from '$lib/components/Toggle.svelte';

const numberOperators = [
{ label: '=', value: 'equal' },
Expand All @@ -40,6 +41,8 @@
let value = '';
let numberValue = 1;
let multilineValue = 'one\ntwo\nthree';

let inputEl: HTMLInputElement | HTMLTextAreaElement | null = null;
</script>

<h1>Examples</h1>
Expand Down Expand Up @@ -225,6 +228,18 @@
/>
</Preview>

<h2>bind:inputEl</h2>

<Preview>
<div class="grid gap-2 justify-start">
<Button on:click={() => inputEl?.focus()}>Manually Focus</Button>
<Toggle let:on={multiline} let:toggle>
<Button on:click={toggle}>{multiline ? 'To single line' : 'To multiline'}</Button>
<TextField label="Name" {multiline} bind:inputEl />
</Toggle>
</div>
</Preview>

<SectionDivider>Type</SectionDivider>

<h2>Input types</h2>
Expand Down
Loading