Skip to content

Weird input validation breakage when using $$props #4418

Closed
@arggh

Description

@arggh

Describe the bug

When passing down unknown props using $$props, like so (Svelma does this, maybe other component libs too?)

<script>
// SvelteInput.svelte

export let value;

$: props = omit($$props, 'value');
</script>

<input type="text" bind:value {...props}/>

...the standard HTML input validation fails when using minlength, like so

<SvelteInput required minlength="5" bind:value={val}/>

The produced HTML seems fine, the input element has both required and minlength="5" set, but the validation doesn't kick in if the input has fewer than 5 characters. If the input is empty, validation works.

If I remove the reactive $: props... assignment and instead pass required and minlength manually, the validation starts working again.

To Reproduce

https://svelte.dev/repl/8da0a0fdbc3245d19e57aeab025e763f?version=3.18.2

Type something into the input. The other one correctly displays the :invalid style, the other one doesn't.

Expected behavior

I'd expect the html input validation to work even when using $: props = ....

Information about your Svelte project:

  • All latest Safari, Firefox, Chrome

  • Mac OS Mojave

  • Svelte version 3.18.2, but checked that the issue exists at least down to 3.7.0

Severity
Breaks validation, but in a very sneaky way, so I'd give it a 7/10 on severity index!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions