mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 10:53:59 +00:00
fix(ui): return Escape focus to the rail item and read rail direction from the panel
A desktop side panel hides once collapsed, so Escape hands focus to its visible rail item instead of the hidden disclosure. Rail selection reads the panel's collapsed class rather than the store, which follows it a microtask late.
This commit is contained in:
1 parent
54b8060f71
commit
231ac4b67b
5 files changed
+81
-5
No files matched your search
@@ -39,10 +39,14 @@ export function bindPanelDisclosure({
|
||||
return { destroy: () => scope.destroy() };
|
||||
}
|
||||
|
||||
/** Close the nearest expanded panel and return focus to its disclosure. */
|
||||
/**
|
||||
* Close the nearest expanded panel and return focus to its disclosure, or to
|
||||
* `returnFocusTo()` when that names a control (a rail item standing in for a
|
||||
* panel that collapsing hid).
|
||||
*/
|
||||
export function collapsePanelOnEscape(
|
||||
event,
|
||||
{ panel, onChange, beforeCollapse },
|
||||
{ panel, onChange, beforeCollapse, returnFocusTo },
|
||||
) {
|
||||
if (event.key !== 'Escape' || event.defaultPrevented) return false;
|
||||
if (
|
||||
@@ -59,6 +63,11 @@ export function collapsePanelOnEscape(
|
||||
event.stopPropagation();
|
||||
beforeCollapse?.();
|
||||
onChange(true, { explicit: true });
|
||||
const stand = returnFocusTo?.();
|
||||
if (stand) {
|
||||
stand.focus?.({ preventScroll: true });
|
||||
return true;
|
||||
}
|
||||
const disclosure =
|
||||
panel.querySelector(`[data-dock-toggle-target="${panel.id}"]`) ||
|
||||
panel.querySelector(`[data-collapse-target="${panel.id}"]`);
|
||||
|
||||
Reference in new issue
Block a user