Skip to content

Fix clicking <Label /> opens <input type="file"> #3707

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

Merged
merged 3 commits into from
Apr 25, 2025
Merged

Conversation

RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Apr 25, 2025

This PR fixes an issue where the <Label> component didn't open the <input type="file"> when clicking it.

For native elements, the Label component already renders a native <label> behind the scenes. Some native elements like <input type="checkbox"> immediately change the state of the element whereas some other elements don't such as <select></select> you just get the focus.

However, <input type="file"> should also immediately open the file picker when clicking the label and this was not the case. This PR fixes that.

Since we are already using a native <label> and linking the <label> with its <input type="file"> performing a .click() is allowed.

Fixes: #3680

Test plan

You can play with it here: https://headlessui-react-git-fix-issue-3680-tailwindlabs.vercel.app/combinations/form

This video shows how it behaves now:

Screen.Recording.2025-04-25.at.12.41.42.mov

Copy link

vercel bot commented Apr 25, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
headlessui-react ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 25, 2025 10:44am
headlessui-vue ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 25, 2025 10:44am

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.

Clicking Label does not open file picker when used in a Field with an Input type="file"
1 participant