From a2324e2165e75f259917bd89e86f1f202368268c Mon Sep 17 00:00:00 2001 From: anor Date: Fri, 6 Nov 2026 23:21:45 +1000 Subject: [PATCH] =?UTF-8?q?fix(=D0=B0=D0=B4=D0=BC=D0=B8=D0=BD=D0=BA=D0=B0)?= =?UTF-8?q?:=20=D1=84=D0=BE=D0=BA=D1=83=D1=81-=D0=BB=D0=BE=D0=B2=D1=83?= =?UTF-8?q?=D1=88=D0=BA=D0=B0=20drawer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/ADMIN_V2_BASELINE.md | 5 +++++ static/admin2/ui/drawer.js | 31 ++++++++++++++++++++++++++----- tests/test_admin_v2_customers.py | 3 +++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/docs/ADMIN_V2_BASELINE.md b/docs/ADMIN_V2_BASELINE.md index c858350..943a67b 100644 --- a/docs/ADMIN_V2_BASELINE.md +++ b/docs/ADMIN_V2_BASELINE.md @@ -351,6 +351,11 @@ - Старый экран: «всех по фильтру»; счётчик «Выбрано N». - Тест: `tests/test_customers_api.py` — 5. +## 4.47. P2.7 follow-up — фокус drawer + +- Drawer фокусирует «Закрыть», Tab/Shift+Tab зациклены, фокус возвращается после закрытия. +- Тест карточки: активный элемент, Shift+Tab внутри, Escape. + ## 5. Следующий шаг P0.0 design-gate → P0.1 backup/restore → P0.2 (release `feat/topup` отдельно, не в рамках выравнивания). diff --git a/static/admin2/ui/drawer.js b/static/admin2/ui/drawer.js index 971f9d3..9079e53 100644 --- a/static/admin2/ui/drawer.js +++ b/static/admin2/ui/drawer.js @@ -1,16 +1,37 @@ import { h } from '/static/admin2/vendor/preact.module.js'; -import { useEffect } from '/static/admin2/vendor/hooks.module.js'; +import { useEffect, useRef } from '/static/admin2/vendor/hooks.module.js'; import htm from '/static/admin2/vendor/htm.module.js'; const html = htm.bind(h); +const FOCUSABLE = 'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'; + export const Drawer = ({ title, onClose, children }) => { + const ref = useRef(null); useEffect(() => { - const esc = (e) => { if (e.key === 'Escape') onClose(); }; - document.addEventListener('keydown', esc); - return () => document.removeEventListener('keydown', esc); + const prev = document.activeElement; + const root = ref.current; + const box = root && root.querySelector('.drawer'); + if (box) { + const first = box.querySelector(FOCUSABLE); + if (first) first.focus(); + } + const onKey = (e) => { + if (e.key === 'Escape') { onClose(); return; } + if (e.key !== 'Tab' || !box) return; + const items = [...box.querySelectorAll(FOCUSABLE)].filter((el) => el.offsetParent !== null); + if (!items.length) return; + const first = items[0], last = items[items.length - 1]; + if (e.shiftKey && document.activeElement === first) { e.preventDefault(); last.focus(); } + else if (!e.shiftKey && document.activeElement === last) { e.preventDefault(); first.focus(); } + }; + document.addEventListener('keydown', onKey); + return () => { + document.removeEventListener('keydown', onKey); + if (prev && prev.focus) prev.focus(); + }; }, [onClose]); return html` -
+