From 0aea4364a142f3db84b77ae99eea1df6a3cd8456 Mon Sep 17 00:00:00 2001 From: Elizabeth Mitchell Date: Fri, 19 Apr 2024 10:24:53 -0700 Subject: [PATCH] fix(dialog): focus is trapped for a11y, use `no-focus-trap` to disable PiperOrigin-RevId: 626403597 --- dialog/demo/demo.ts | 4 + dialog/demo/stories.ts | 29 ++++--- dialog/internal/dialog.ts | 171 +++++++++++++++++++++++++++++++++----- 3 files changed, 172 insertions(+), 32 deletions(-) diff --git a/dialog/demo/demo.ts b/dialog/demo/demo.ts index b8d669cc1..f64eacfed 100644 --- a/dialog/demo/demo.ts +++ b/dialog/demo/demo.ts @@ -24,6 +24,10 @@ const collection = new MaterialCollection>( defaultValue: false, ui: boolInput(), }), + new Knob('noFocusTrap', { + defaultValue: false, + ui: boolInput(), + }), new Knob('icon', {defaultValue: '', ui: textInput()}), new Knob('headline', {defaultValue: 'Dialog', ui: textInput()}), new Knob('supportingText', { diff --git a/dialog/demo/stories.ts b/dialog/demo/stories.ts index e41083709..3a56b7dc6 100644 --- a/dialog/demo/stories.ts +++ b/dialog/demo/stories.ts @@ -20,6 +20,7 @@ import {css, html, nothing} from 'lit'; /** Knob types for dialog stories. */ export interface StoryKnobs { quick: boolean; + noFocusTrap: boolean; icon: string; headline: string; supportingText: string; @@ -31,7 +32,7 @@ function showDialog(event: Event) { const standard: MaterialStoryInit = { name: 'Dialog', - render({icon, headline, supportingText, quick}) { + render({icon, headline, supportingText, quick, noFocusTrap}) { return html` Open @@ -39,7 +40,8 @@ const standard: MaterialStoryInit = { + ?quick=${quick} + ?no-focus-trap=${noFocusTrap}> ${icon ? html`${icon}` : nothing}
${headline}
@@ -56,13 +58,13 @@ const standard: MaterialStoryInit = { const alert: MaterialStoryInit = { name: 'Alert', - render({quick}) { + render({quick, noFocusTrap}) { return html` Alert - +
Alert dialog
This is a standard alert dialog. Alert dialogs interrupt users with @@ -78,7 +80,7 @@ const alert: MaterialStoryInit = { const confirm: MaterialStoryInit = { name: 'Confirm', - render({quick}) { + render({quick, noFocusTrap}) { return html` = { Confirm - +
Permanently delete?
delete_outline @@ -112,13 +117,13 @@ const choose: MaterialStoryInit = { align-items: center; } `, - render({quick}) { + render({quick, noFocusTrap}) { return html` Choice - +
Choose your favorite pet