From f71cfee90f950f3982cec1aa8410b8f029767f6a Mon Sep 17 00:00:00 2001 From: ShaneK Date: Fri, 23 Oct 2026 13:42:08 -0700 Subject: [PATCH] fix(alert): only block Enter on checkbox inputs, not the whole document --- core/src/components/alert/alert.tsx | 19 +++--- .../components/alert/test/a11y/alert.e2e.ts | 63 +++++++++++++++++++ 2 files changed, 73 insertions(+), 9 deletions(-) diff --git a/core/src/components/alert/alert.tsx b/core/src/components/alert/alert.tsx index de8d7bd450d..27095b1326f 100644 --- a/core/src/components/alert/alert.tsx +++ b/core/src/components/alert/alert.tsx @@ -238,15 +238,6 @@ export class Alert implements ComponentInterface, OverlayInterface { onKeydown(ev: any) { const inputTypes = new Set(this.processedInputs.map((i) => i.type)); - /** - * Based on keyboard navigation requirements, the - * checkbox should not respond to the enter keydown event. - */ - if (inputTypes.has('checkbox') && ev.key === 'Enter') { - ev.preventDefault(); - return; - } - /** * Ensure when alert container is being focused, and the user presses the tab + shift keys, the focus will be set to the last alert button. */ @@ -525,6 +516,15 @@ export class Alert implements ComponentInterface, OverlayInterface { forceUpdate(this); } + /** + * Prevent Enter from toggling the checkbox, which only Space should do. + */ + private onCheckboxKeydown = (ev: KeyboardEvent) => { + if (ev.key === 'Enter') { + ev.preventDefault(); + } + }; + private async buttonClick(button: AlertButton) { const role = button.role; const values = this.getValues(); @@ -625,6 +625,7 @@ export class Alert implements ComponentInterface, OverlayInterface {