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 3 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
49 changes: 42 additions & 7 deletions src/svelte/components/ListInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
{:else}
<!-- svelte-ignore a11y-autofocus -->
{#if type === 'select'}
<svelte:element
<select
this={InputComponent}
Copy link
Contributor

Choose a reason for hiding this comment

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

Here and in the other cases, is this still needed? I thought this is what determined what tag was used when using svelte:element.

Copy link
Author

Choose a reason for hiding this comment

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

You're right. It's not necessary, but I left it there to minimize code changes. I'll remove it (along with some other unnecessary lines), as I've already made more changes than I initially expected.

id={inputId}
bind:this={inputEl}
Expand All @@ -217,28 +217,63 @@
{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'}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit, but I'd do:

Suggested change
{:else if type !== 'textarea'}
{:else if type === 'textarea'}
<textarea ... />
{:else}
<input ... />

<input
this={InputComponent}
id={inputId}
bind:this={inputEl}
class={c.input[labelStyleIsFloating]}
style={inputStyle}
{name}
{...{ type }}
{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}
/>
{:else}
<svelte:element
<textarea
this={InputComponent}
id={inputId}
bind:this={inputEl}
class={c.input[labelStyleIsFloating]}
style={inputStyle}
{name}
type={needsType ? type : undefined}
{placeholder}
{inputmode}
{size}
Expand All @@ -260,7 +295,7 @@
{required}
{pattern}
{tabindex}
{value}
bind:value
on:input={onInput}
on:change={onChange}
on:focus={onFocusInternal}
Expand Down