fix(utils): remove unnecessary keyboard utils (#146)

This commit is contained in:
Wesley Luyten
2025-10-29 15:17:08 -05:00
committed by GitHub
parent 2ff96ded8f
commit b737758453
4 changed files with 1 additions and 54 deletions
-3
View File
@@ -37,9 +37,6 @@
"test": "echo \"No tests yet\"",
"clean": "rm -rf dist"
},
"dependencies": {
"tabbable": "^6.2.0"
},
"devDependencies": {
"tsdown": "^0.15.9",
"typescript": "^5.9.2"
-1
View File
@@ -1,6 +1,5 @@
export * from './attributes';
export * from './element';
export * from './event';
export * from './keyboard';
export * from './safe-polygon';
export * from './shadow-dom';
-46
View File
@@ -1,46 +0,0 @@
import type { FocusableElement } from 'tabbable';
import { tabbable } from 'tabbable';
import { activeElement, getDocument } from './element';
export function getTabbableOptions(): Readonly<{
getShadowRoot: boolean;
displayCheck: 'full' | 'none';
}> {
// JSDOM does not support the `tabbable` library. To solve this we can
// check if `ResizeObserver` is a real function (not polyfilled), which
// determines if the current environment is JSDOM-like.
const isNativeResizeObserver: boolean = typeof ResizeObserver === 'function' && ResizeObserver.toString().includes('[native code]');
const displayCheck: 'full' | 'none' = isNativeResizeObserver ? 'full' : 'none';
return ({
getShadowRoot: true,
displayCheck: displayCheck as 'full' | 'none',
}) as const;
}
function getTabbableIn(container: HTMLElement, dir: 1 | -1): FocusableElement | undefined {
const list = tabbable(container, getTabbableOptions());
const len = list.length;
if (len === 0) {
return undefined;
}
const active = activeElement(getDocument(container)) as FocusableElement;
const index = list.indexOf(active);
const nextIndex = index === -1 ? (dir === 1 ? 0 : len - 1) : index + dir;
return list[nextIndex];
}
export function getNextTabbable(referenceElement: Element | null): FocusableElement | null {
return (
getTabbableIn(getDocument(referenceElement).body, 1) || (referenceElement as FocusableElement)
);
}
export function getPreviousTabbable(referenceElement: Element | null): FocusableElement | null {
return (
getTabbableIn(getDocument(referenceElement).body, -1) || (referenceElement as FocusableElement)
);
}
+1 -4
View File
@@ -243,10 +243,6 @@ importers:
version: 5.9.3
packages/utils:
dependencies:
tabbable:
specifier: ^6.2.0
version: 6.2.0
devDependencies:
tsdown:
specifier: ^0.15.9
@@ -4876,6 +4872,7 @@ packages:
sitemap@8.0.0:
resolution: {integrity: sha512-+AbdxhM9kJsHtruUF39bwS/B0Fytw6Fr1o4ZAIAEqA6cke2xcoO2GleBw9Zw7nRzILVEgz7zBM5GiTJjie1G9A==}
engines: {node: '>=14.0.0', npm: '>=6.0.0'}
deprecated: 'SECURITY: Multiple vulnerabilities fixed in 8.0.1 (XML injection, path traversal, command injection, protocol injection). Upgrade immediately: npm install sitemap@8.0.1'
hasBin: true
slice-ansi@7.1.2: