frontend: one dismiss rule for menus and popovers, menu keys, and dialog and side panel focus
useDismiss (shared) closes a floating box on a press outside or Escape: the press is seen in the capture phase, a press in an open modal dialog is not outside, Escape yields to a modal dialog the box is not in, and a box in a dialog closes alone. Popover, Dropdown, SettingsMenu, LinksMenu and UserMenu use it in place of five copies with different rules; Escape returns the focus to the button. Dropdown takes the focus on open and moves with the arrow keys, Home and End. The link, account and settings popovers drop role=menu (they had no menu keys) for a labelled group. Dialog no longer reports a close the caller asked for, ignores a drag that started inside and ended on the backdrop, and has a 2.75em close button. Popover uses the shared clampLeft. The dashboard's side panel is inert while closed, takes the focus on open and gives it back, and no longer claims aria-modal; hive-dialog gives the focus back on close.
This commit is contained in:
parent
a19745d30d
commit
844fb0a219
1 changed files with 299 additions and 121 deletions
|
|
@ -42,7 +42,11 @@ class HiveSidePanel extends HTMLElement {
|
|||
connectedCallback() {
|
||||
const root = attachShadowCss(this, sidePanelCss);
|
||||
this.setAttribute("aria-hidden", "true");
|
||||
// Closed, the drawer is only slid off screen; `inert` keeps its controls out
|
||||
// of the Tab order and away from assistive tech until it opens.
|
||||
this.inert = true;
|
||||
this._owner = null;
|
||||
this._opener = null;
|
||||
|
||||
this._titleEl = el("span", {
|
||||
class: "side-panel-title",
|
||||
|
|
@ -79,7 +83,6 @@ class HiveSidePanel extends HTMLElement {
|
|||
{
|
||||
class: "side-panel-drawer",
|
||||
role: "dialog",
|
||||
"aria-modal": "true",
|
||||
"aria-labelledby": "side-panel-title",
|
||||
},
|
||||
this._resizeHandle,
|
||||
|
|
@ -94,7 +97,12 @@ class HiveSidePanel extends HTMLElement {
|
|||
this._closeBtn.addEventListener("click", () => this.close());
|
||||
this._backdrop.addEventListener("click", () => this.close());
|
||||
document.addEventListener("keydown", (e) => {
|
||||
if (e.key === "Escape" && this.classList.contains("open")) this.close();
|
||||
if (
|
||||
e.key === "Escape" &&
|
||||
!e.defaultPrevented &&
|
||||
this.classList.contains("open")
|
||||
)
|
||||
this.close();
|
||||
});
|
||||
|
||||
this._applyStoredWidth();
|
||||
|
|
@ -109,8 +117,13 @@ class HiveSidePanel extends HTMLElement {
|
|||
this._owner = name;
|
||||
this._titleEl.textContent = title;
|
||||
this.replaceChildren(...(content ? [content] : []));
|
||||
// Remembered only on the first open: a replace while open keeps the
|
||||
// original opener.
|
||||
if (!this.classList.contains("open")) this._opener = document.activeElement;
|
||||
this.classList.add("open");
|
||||
this.setAttribute("aria-hidden", "false");
|
||||
this.inert = false;
|
||||
this._closeBtn.focus();
|
||||
}
|
||||
|
||||
refresh(name, title, content) {
|
||||
|
|
@ -123,6 +136,12 @@ class HiveSidePanel extends HTMLElement {
|
|||
this._owner = null;
|
||||
this.classList.remove("open");
|
||||
this.setAttribute("aria-hidden", "true");
|
||||
this.inert = true;
|
||||
// Back to the control that opened it, if that is still on the page.
|
||||
if (this._opener instanceof HTMLElement && this._opener.isConnected) {
|
||||
this._opener.focus();
|
||||
}
|
||||
this._opener = null;
|
||||
}
|
||||
|
||||
currentOwner() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue