Closed Bug 1583097 Opened 6 years ago Closed 6 years ago

event.preventDefault does not work on select

Categories

(Core :: DOM: UI Events & Focus Handling, defect)

70 Branch
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 1019630
Tracking Status
firefox69 --- affected
firefox70 --- affected
firefox71 --- affected

People

(Reporter: Johannes.Giske, Unassigned)

Details

Attachments

(6 files)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0

Steps to reproduce:

Use the following HTML and Javascript. Then tab to focus the select and press the space key.

CodePen with the same code: https://codepen.io/johgis/pen/oNvJmoJ

<script>
const onKeyDown = event => {
if (event.key === ' ') {
console.log('Prevent default');
event.preventDefault();
}
}
</script>

<label for="test">Test</label>
<select id="test" onkeydown="javascript:onKeyDown(event)">
<option value="1">Test 1</option>
<option value="2">Test 2</option>
<option value="3">Test 3</option>
<option value="4">Test 4</option>
</select>

Actual results:

The select opens and renders a list of options. The console logs 'Prevent default' proving that event.preventDefault() was triggered.

Expected results:

The select should not open. The console should still log 'Prevent default'.
I have tested this code in Chrome, Edge and Vivaldi and all these have the expected behavior.

Hi Johannes,

Thank you for your report.

Could you give us further steps for reproduction? I open the test page https://codepen.io/johgis/pen/oNvJmoJ but I'm not sure in which element of the page I need to focus the Tab key to then press the space key. Are you referring to the html element </select>?

If you can add screenshots or a screen recording to this ticket it'll help a lot.

Also, please let us know if you can reproduce the issue using the latest Firefox Nightly, you can download it here: https://nightly.mozilla.org

Regards,

Flags: needinfo?(Johannes.Giske)

Hi Virginia, you should focus the <select>. I've updated the code here (https://codepen.io/johgis/pen/oNvJmoJ) to add an red border around the select when it's focused.

I don't have a way to make a screen recording at the moment, but I'll add a few screenshots.

Flags: needinfo?(Johannes.Giske)
Attached image edge: select
Attached image edge: select, focused

Hey Johannes,

Thanks so much for providing further information. I was able to reproduce the behavior reported on Windows 10 and Mac OSX 10.14 using:

  • Firefox Nightly 71.0a1 (2019-09-30) (64-bit),
  • Firefox Beta 70.0b10 (64-bit)
  • Firefox Release 69.0.1 (64-bit)

I'll add a product and component so the dev team can take a look at this. Feel free to change it for a more appropriate one.

Regards,

Status: UNCONFIRMED → NEW
Component: Untriaged → User events and focus handling
Ever confirmed: true
Product: Firefox → Core
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: