Skip to content

Switch from KeyboardEvent.keyCode to KeyboardEvent.code #952

Closed
@robinmetral

Description

@robinmetral

Hi! First of all, apologies for removing the issue template—since this isn't a bug report, I've found it hard to fill the reproduction steps.

I'm wondering if there's anything stopping us from switching from the deprecated KeyboardEvent.keyCode to KeyboardEvent.code in the ModalPortal:

handleKeyDown = event => {
if (event.keyCode === TAB_KEY) {
scopeTab(this.content, event);
}
if (this.props.shouldCloseOnEsc && event.keyCode === ESC_KEY) {
event.stopPropagation();
this.requestClose(event);
}
};

We should probably stop relying on the deprecated property, and since React 18 dropped support for IE (which didn't support KeyboardEvent.code), I can't think of any blockers.

Using the deprecated property can already cause issues in browsers (or testing environments) that have removed support for it. I've ran into this using @testing-library/user-event (ref).

Happy to submit a PR for this!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions