Skip to content

bug(MatSelect): Key bindings only defined by KeyboardEvent#keyCode #31875

@PriyankaSPX

Description

@PriyankaSPX

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

https://github.com/angular/material/blob/952c06705a7eddaa02fcbb2fd931e06740702404/src/components/select/select.js#L1835

KeyboardEvent#keyCode is deprecated, but the Select component key bindings are only defined according to keyCode, not KeyboardEvent#key or KeyboardEvent#code. In our use case we wish to test that the default SPACE key event handling is carried out by the Select component, given that we are overriding the keydown event handler for other keys. However we cannot trigger the event handler in the test by dispatching a KeyboardEvent without the "SPACE" keyCode present on the event. Ideally we should be able to pass an event with the key property for SPACE instead.

Reproduction

StackBlitz not relevant

Expected Behavior

Dispatching a KeyboardEvent with key: " " should trigger the default MatSelect keydown handler behaviour for a space key press.

Actual Behavior

This does not happen unless the event also has keyCode: 32 defined.

Environment

  • Angular: 19.0.0
  • CDK/Material: 19.0.0
  • Browser(s): Google Chrome 140.0.7339.80 (Official Build) (64-bit)
  • Operating System (e.g. Windows, macOS, Ubuntu): Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4A relatively minor issue that is not relevant to core functions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions