Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to use the Enter-key on a file input's label to open the file browser

I have a file input, with a label. I wish to be able to open the file browser in four different ways:

  1. Clicking the file input button
  2. Tabbing to the file input button and hitting enter
  3. Clicking the file input label
  4. Tabbing to the file input label and hitting enter

However, only options 1-3 work out of the box? Is this a bug, or an intended feature? I’m currently working on FireFox v106.0.5

Are there any solutions out there that rely solely on HTML/CSS, or is JS required to fix the issue?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<label for="file_input" tabindex="0">
  Label
</label>
<input type="file" id="file_input">

>Solution :

Naturally, the input opens a dialog when it receives click or enter.

The label itself does not open a dialog, but when clicked (or tapped), it can passes the focus to its associated input, and a dialog is opened as a result.

It does not do the same when it receives enter, thus the situation 4 in your question does not work.

This is because the purpose of this design is to increase the hit size for the associated input, especially for user on a touch-screen device.

So to answer the question, it is an intended feature.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading