회기 무발화 0턴 분리, 자기예측 락 불변식 및 TDD 회귀 검증 완료
Some checks failed
API contract / OpenAPI type drift (push) Failing after 3m27s
Some checks failed
API contract / OpenAPI type drift (push) Failing after 3m27s
This commit is contained in:
parent
a479db7a5a
commit
a0311c5957
100 changed files with 4884 additions and 11210 deletions
21
apps/web/src/lib/focusTrap.ts
Normal file
21
apps/web/src/lib/focusTrap.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
const FOCUSABLE_SELECTOR =
|
||||
"a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex='-1'])";
|
||||
|
||||
export function getFocusableControls(root: HTMLElement | null): HTMLElement[] {
|
||||
return Array.from(root?.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR) ?? []).filter(
|
||||
(control) => control.getClientRects().length > 0,
|
||||
);
|
||||
}
|
||||
|
||||
export function trapTabKey(event: KeyboardEvent, controls: readonly HTMLElement[]): void {
|
||||
if (event.key !== "Tab" || controls.length === 0) return;
|
||||
const first = controls[0];
|
||||
const last = controls[controls.length - 1];
|
||||
if (event.shiftKey && document.activeElement === first) {
|
||||
event.preventDefault();
|
||||
last.focus();
|
||||
} else if (!event.shiftKey && document.activeElement === last) {
|
||||
event.preventDefault();
|
||||
first.focus();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue