From 61e5e87106d09fd43ae82828f6645e0444ae1b10 Mon Sep 17 00:00:00 2001 From: Elliott Marquez Date: Mon, 26 Jun 2023 15:25:11 -0700 Subject: [PATCH] fix(dialog): focus before animation to fix a11y PiperOrigin-RevId: 543557352 --- dialog/lib/dialog.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dialog/lib/dialog.ts b/dialog/lib/dialog.ts index 1238df2eaf..b41ab22494 100644 --- a/dialog/lib/dialog.ts +++ b/dialog/lib/dialog.ts @@ -379,6 +379,10 @@ export class Dialog extends LitElement { private async performTransition(shouldDispatchAction: boolean) { // TODO: pause here only to avoid a double update warning. await this.updateComplete; + // Focus initial element. + if (this.open) { + this.focus(); + } this.showingOpen = this.open; if (shouldDispatchAction) { this.dispatchActionEvent(this.open ? 'opening' : 'closing'); @@ -415,10 +419,6 @@ export class Dialog extends LitElement { Dialog.setDocumentScrollingDisabled(this.open); } } - // Focus initial element. - if (this.open) { - this.focus(); - } if (shouldDispatchAction) { this.dispatchActionEvent(this.open ? 'opened' : 'closed'); }