1
0
mirror of https://github.com/robonen/tools.git synced 2026-03-20 10:54:44 +00:00

feat(vue/primitives): add FocusScope component with auto-focus and focus trap functionality

This commit is contained in:
2026-03-10 18:28:52 +07:00
parent a996eb74b9
commit 4574bae0b6
36 changed files with 1266 additions and 65 deletions

View File

@@ -0,0 +1,29 @@
export interface FocusScopeAPI {
paused: boolean;
pause: () => void;
resume: () => void;
}
const stack: FocusScopeAPI[] = [];
export function createFocusScopesStack() {
return {
add(focusScope: FocusScopeAPI) {
const current = stack.at(-1);
if (focusScope !== current) current?.pause();
// Remove if already in stack (deduplicate), then push to top
const index = stack.indexOf(focusScope);
if (index !== -1) stack.splice(index, 1);
stack.push(focusScope);
},
remove(focusScope: FocusScopeAPI) {
const index = stack.indexOf(focusScope);
if (index !== -1) stack.splice(index, 1);
stack.at(-1)?.resume();
},
};
}