Firefox file dialog not opening via JavaScript when triggered by keyboard shortcut with CTRL or ALT modifiers
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
People
(Reporter: dswitzer, Unassigned)
References
(Blocks 1 open bug)
Details
Attachments
(1 file)
|
1.53 KB,
text/html
|
Details |
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:134.0) Gecko/20100101 Firefox/134.0
Steps to reproduce:
When triggering the file dialog to open via a JavaScript keyboard shortcut, Firefox will not always open the dialog when either the Control or Alt modifiers are being held. When the modifiers are not held, it always works as expected.
I've attached an example (file_input_keyboard_issue.html) which illustrates the behavior, but the behavior can be seen with the following code:
HTML:
<input type="file" id="fileInput" />
JavaScript:
document.addEventListener('keydown', function(event){
if( (event.key.toLowerCase() == "a") ){
event.preventDefault();
console.log("Open dialog!", (new Date()).getTime());
document.getElementById('fileInput').click();
}
});
Using the above code, pressing the letter "A" will always trigger the file upload dialog, but if you press and hold any combination of CTRL or ALT then it will not always work.
You can see this by opening the dialog, then clicking the "Cancel" button and pressing CTRL+A. When you do this, the dialog will not open unless you click somewhere on the page, but if you just press "A" it will work as expected.
I've tried many different keycodes besides "A" and they all exhibit the same behavior.
Actual results:
If you do not click somewhere in the DOM (after canceling the file dialog via the "Cancel" button or pressing [ESC] key), then pressing CTRL+A, ALT+A or CTRL+ALT+A wire dispatch the events as expected, but the file dialog will not open. If this happens, you can click anywhere in the DOM and then repeat the keyboard command it will open.
then nothing will happen if the file dialog was canceled, but the events are fired as expected
Expected results:
A keyboard modifier should not prevent the file dialog from opening. It should always open just as it does when neither the CTRL nor ALT modifiers are pressed.
| Reporter | ||
Comment 1•1 year ago
|
||
I'm not sure when this problem started, but I suspect it's been around a while.
Comment 2•1 year ago
|
||
The Bugbug bot thinks this bug should belong to the 'Firefox::Keyboard Navigation' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.
Comment 3•1 year ago
|
||
The severity field is not set for this bug.
:dao, could you have a look please?
For more information, please visit BugBot documentation.
Comment 4•1 year ago
|
||
Hello! Thank you for submitting this issue.
I have managed to reproduce the issue with firefox 137.0a1(2025) and 135.0 on Ubuntu 22.04 with the steps provided in the description.
I will mark this issue as NEW in order to get our developers involved and provide a solution for this issue.
Have a nice day!
| Reporter | ||
Comment 5•1 year ago
|
||
I'm glad the example repo was sufficient to demonstrate the problem. Seems like a minor issue, but I thought it might be hiding a bigger issue w/keyboard events.
Comment 6•1 year ago
|
||
Yes, I think this is expected based on our code CanUserGestureActivateTarget not allowing most combinations with special keys.
Comment 7•1 year ago
|
||
Since nightly and release are affected, beta will likely be affected too.
For more information, please visit BugBot documentation.
| Reporter | ||
Comment 8•1 year ago
|
||
(In reply to Tom Schuster from comment #6)
Yes, I think this is expected based on our code
CanUserGestureActivateTargetnot allowing most combinations with special keys.
Just to be clear, pressing the keyboard modifier usually does work the first time, but will stop working until you interact with the page again (by like clicking somewhere in the page).
It's like the opening of the file dialog puts the "focus" of the window in some kind of weird state, but if you click in the DOM to force focus back, then the pressing the modifiers works again.
NOTE - Doing something like window.focus() does not fix the problem.
Updated•1 year ago
|
Updated•7 months ago
|
Description
•