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

fix: Add files and group properties to HTMLInputAttributes #15492

Merged

Conversation

dvcol
Copy link
Contributor

@dvcol dvcol commented Mar 11, 2025

This adds missing files and group properties to match the respective bind:files and bind:group.

Unless I'm mistaken, it seems that the files and group attributes are missing from the HTMLInputAttributes type in element.d.ts.

The typings for the binding 'bind:group' and 'bind:files' are present (as seen here) but the individual properties aren't.

Note that the bindings exists on the deprecated SvelteInputProps, so maybe this is intentional somehow ?

Closes issue #14579

dvcol and others added 2 commits March 11, 2025 18:45
Adds missing `files` and `group` to match the respective `bind:files` and `bind:group`.
Copy link

changeset-bot bot commented Mar 11, 2025

🦋 Changeset detected

Latest commit: fec6912

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Rich-Harris
Copy link
Member

Ah, interesting — hadn't noticed the prop typing issue. The fix you propose definitely makes sense for files since setting files works.

For group it's slightly less clear-cut — the types here would imply that you could do this (note the lack of bind)...

<!-- is checked when `choice === 'one'` -->
<input type="radio" group={choice} value="one" />

...but you can't, it just (uselessly/confusingly) sets a group attribute on the element. So now I'm wondering if it's better to let the types lie a little bit, or change the behaviour of group so that the above works (which would be a can of worms when considering spread attributes).

@dummdidumm
Copy link
Member

I vote for "lie a bit" - I cannot imagine someone tripping up on that in practise.

@dvcol
Copy link
Contributor Author

dvcol commented Mar 12, 2025

What about making it condition on the input type ?

interface HTMLInputAttributes<Type extends HTMLInputTypeAttribute | undefined | null = undefined> extends HTMLAttributes<HTMLInputElement> {
	...
	group?: Type extends 'checkbox' | 'radio' ? any | undefined | null : never;
        ...
}

However, doesn't this issues also exist for other specific bindings, like checked and indeterminate ?

@paoloricciuti
Copy link
Member

What about making it condition on the input type ?

interface HTMLInputAttributes<Type extends HTMLInputTypeAttribute | undefined | null = undefined> extends HTMLAttributes<HTMLInputElement> {
	...
	group?: Type extends 'checkbox' | 'radio' ? any | undefined | null : never;
        ...
}

However, doesn't this issues also exist for other specific bindings, like checked and indeterminate ?

This wouldn't solve the issue @Rich-Harris is talking about tho

@dvcol
Copy link
Contributor Author

dvcol commented Mar 12, 2025

Not completely, but it would restrict it to the checkbox and radio inputs, lessen the lie in some way ?

@dvcol dvcol changed the title feat: Add files and group properties to HTMLInputAttributes fix: Add files and group properties to HTMLInputAttributes Mar 12, 2025
@Rich-Harris
Copy link
Member

I don't think it's possible — unless I'm missing something there's nowhere for us to pass the right type argument, so Type will always be undefined which causes this:

image

I'm good with 'lie a bit' too so I'll merge this as-is. Thanks!

Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@15492

@dummdidumm dummdidumm merged commit b27ca42 into sveltejs:main Mar 12, 2025
9 checks passed
@github-actions github-actions bot mentioned this pull request Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants