You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<Field className="mb-4 flex flex-col">
<Label>Headless UI Field and Label</Label>
<Input type={'file'} />
</Field>
<div className="mb-4 flex flex-col">
<label htmlFor={'raw-input'}>Raw HTML Label</label>
<Input id={'raw-input'} type={'file'} />
</div>
Describe your issue
Clicking on a Label component that is attached to an Input element of type "file" does not open the file picker. This is different to a standard HTML <label>, which will open the file picker when clicked, both with a standard <input> element and the Headless UI Input component.
The text was updated successfully, but these errors were encountered:
Hello @EPurwanto
Thanks for the clear reproduction - I’ve also run into this exact problem.
The core issue is that Headless UI’s <Label> component does not replicate native <label> behavior for <input type="file">. While it successfully manages focus and accessibility for ARIA widgets, it uses a synthetic .click() on the target element, which browsers block for file inputs unless the event is a trusted, native user gesture. This prevents the file picker from opening.(see MDN, Chromium source)
Additionally, the component always applies aria-labelledby, even when it’s empty. According to the ARIA in HTML spec and accessible name computation spec, this overrides the implicit htmlFor → id linkage, further breaking expected behavior.
Limitations:
<Label> triggers .click() programmatically — this does not open file pickers reliably (MDN, Chromium source).
Hope this helps others running into the same limitation or at least describes the cause.
Edit: neglected to tag OP
Update: Even with a native <input type="file">, using Headless UI’s <Label> inside a <Field> can still block the file picker. This happens because <Label> participates in internal context and calls event.preventDefault(), which suppresses the browser’s native behavior.
What package within Headless UI are you using?
@headlessui/react
What version of that package are you using?
2.2.1
What browser are you using?
Tested in Chrome and Firefox
Reproduction URL
https://codesandbox.io/p/devbox/headless-ui-file-label-v5rlnq
The structure is just this:
Describe your issue
Clicking on a
Label
component that is attached to anInput
element of type "file" does not open the file picker. This is different to a standard HTML<label>
, which will open the file picker when clicked, both with a standard<input>
element and the Headless UIInput
component.The text was updated successfully, but these errors were encountered: