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

svelte: enable two-way binding for ListInput component #213

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
54 changes: 41 additions & 13 deletions src/svelte/components/ListInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@
className,
(v) => (c = v)
);

$: InputComponent = type === 'select' || type === 'textarea' ? type : 'input';
$: needsType = InputComponent === 'input';
</script>

<ListItem
Expand Down Expand Up @@ -193,14 +190,12 @@
{:else}
<!-- svelte-ignore a11y-autofocus -->
{#if type === 'select'}
<svelte:element
this={InputComponent}
<select
id={inputId}
bind:this={inputEl}
class={c.input[labelStyleIsFloating]}
style={inputStyle}
{name}
type={needsType ? type : undefined}
{placeholder}
{inputmode}
{size}
Expand All @@ -217,28 +212,61 @@
{min}
{minlength}
{step}
{multiple}
{...{ multiple }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean the value of multiple on the select element won't change if the parent changes the multiple value it's passing in? I.e., the parent can set it, but then can't change it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the component will update when the parent changes the value. This line just bypasses Svelte's static check.

{readonly}
{required}
{pattern}
{tabindex}
{value}
bind:value
on:input={onInput}
on:change={onChange}
on:focus={onFocusInternal}
on:blur={onBlurInternal}
>
<slot />
</svelte:element>
</select>
{:else if type === 'textarea'}
<textarea
id={inputId}
bind:this={inputEl}
class={c.input[labelStyleIsFloating]}
style={inputStyle}
{name}
{placeholder}
{inputmode}
{size}
{accept}
{autocomplete}
{autocorrect}
{autocapitalize}
{spellcheck}
{autofocus}
{autosave}
{disabled}
{max}
{maxlength}
{min}
{minlength}
{step}
{multiple}
{readonly}
{required}
{pattern}
{tabindex}
bind:value
on:input={onInput}
on:change={onChange}
on:focus={onFocusInternal}
on:blur={onBlurInternal}
></textarea>
{:else}
<svelte:element
this={InputComponent}
<input
id={inputId}
bind:this={inputEl}
class={c.input[labelStyleIsFloating]}
style={inputStyle}
{name}
type={needsType ? type : undefined}
{...{ type }}
{placeholder}
{inputmode}
{size}
Expand All @@ -260,7 +288,7 @@
{required}
{pattern}
{tabindex}
{value}
bind:value
on:input={onInput}
on:change={onChange}
on:focus={onFocusInternal}
Expand Down