diff --git a/src/elements/ia-item-navigator/ia-item-navigator.ts b/src/elements/ia-item-navigator/ia-item-navigator.ts index c88808e..ef66ee5 100644 --- a/src/elements/ia-item-navigator/ia-item-navigator.ts +++ b/src/elements/ia-item-navigator/ia-item-navigator.ts @@ -248,23 +248,30 @@ export class IAItemNavigator toggleMenu(forceValue: boolean | undefined = undefined): void { this.menuOpened = forceValue !== undefined ? forceValue : !this.menuOpened; - if (this.menuOpened) { - // Move focus to the - this.updateComplete.then(() => { - const closeButton = this.menuSlider?.shadowRoot?.querySelector( - 'button.close', - ) as HTMLElement; - closeButton?.focus(); - }); - } else { - // Move focus back to the menu toggle button - this.updateComplete.then(() => { + this.moveFocusForDrawer(); + } + + /** + * Opening the drawer moves focus into it; closing hands focus back to the + * toggle. Without this, opening from the shortcut rail would leave focus on + * a button that is about to be hidden, dropping it to the document. + */ + private moveFocusForDrawer(): void { + this.updateComplete.then(() => { + if (this.menuOpened) { + this.menuSlider?.focusDrawer(); + } else { this.toggleMenuButton?.focus(); - }); - } + } + }); } + /** + * Closing the drawer also closes whatever panel was open inside it, so the + * two can't disagree and a stale panel can't reappear on the next open. + */ closeMenu(): void { + this.openMenu = undefined; this.toggleMenu(false); } @@ -307,13 +314,15 @@ export class IAItemNavigator } get menuToggleButton(): TemplateResult { + const label = this.menuOpened ? 'Close side panel' : 'Open side panel'; return html` @@ -326,22 +335,27 @@ export class IAItemNavigator get renderSideMenu(): TemplateResult { return html` -