Skip to content

Commit f23d14c

Browse files
committed
feat(deep-active-element): create deep-active-element package
1 parent 36d954d commit f23d14c

File tree

6 files changed

+102
-0
lines changed

6 files changed

+102
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `deep-active-element`
2+
3+
This package contains a utility to get the currently focused element even across Shadow DOM boundaries.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @ts-check
2+
import { configs } from '@repo/eslint-config/react-package';
3+
4+
export default configs;
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"name": "@radix-ui/deep-active-element",
3+
"version": "1.0.0",
4+
"license": "MIT",
5+
"source": "./src/index.ts",
6+
"main": "./src/index.ts",
7+
"module": "./src/index.ts",
8+
"publishConfig": {
9+
"main": "./dist/index.js",
10+
"module": "./dist/index.mjs",
11+
"types": "./dist/index.d.ts",
12+
"exports": {
13+
".": {
14+
"import": {
15+
"types": "./dist/index.d.mts",
16+
"default": "./dist/index.mjs"
17+
},
18+
"require": {
19+
"types": "./dist/index.d.ts",
20+
"default": "./dist/index.js"
21+
}
22+
}
23+
}
24+
},
25+
"files": [
26+
"dist",
27+
"README.md"
28+
],
29+
"sideEffects": false,
30+
"scripts": {
31+
"lint": "eslint --max-warnings 0 src",
32+
"clean": "rm -rf dist",
33+
"typecheck": "tsc --noEmit",
34+
"build": "radix-build"
35+
},
36+
"dependencies": {
37+
"@radix-ui/react-primitive": "workspace:*"
38+
},
39+
"peerDependencies": {
40+
"@types/react": "*",
41+
"@types/react-dom": "*",
42+
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
43+
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
44+
},
45+
"peerDependenciesMeta": {
46+
"@types/react": {
47+
"optional": true
48+
},
49+
"@types/react-dom": {
50+
"optional": true
51+
}
52+
},
53+
"devDependencies": {
54+
"@repo/builder": "workspace:*",
55+
"@repo/eslint-config": "workspace:*",
56+
"@repo/typescript-config": "workspace:*",
57+
"@types/react": "^19.0.7",
58+
"@types/react-dom": "^19.0.3",
59+
"eslint": "^9.18.0",
60+
"react": "^19.1.0",
61+
"react-dom": "^19.1.0",
62+
"typescript": "^5.7.3"
63+
},
64+
"homepage": "https://radix-ui.com/primitives",
65+
"repository": {
66+
"type": "git",
67+
"url": "git+https://github.com/radix-ui/primitives.git"
68+
},
69+
"bugs": {
70+
"url": "https://github.com/radix-ui/primitives/issues"
71+
}
72+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Utility to get the currently focused element even across Shadow DOM boundaries
3+
*/
4+
export function getDeepActiveElement(): Element | null {
5+
let activeElement = document.activeElement;
6+
7+
// Traverse through shadow DOMs to find the deepest active element
8+
while (activeElement && activeElement.shadowRoot && activeElement.shadowRoot.activeElement) {
9+
activeElement = activeElement.shadowRoot.activeElement;
10+
}
11+
12+
return activeElement;
13+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { getDeepActiveElement } from './deep-active-element';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "@repo/typescript-config/react-library.json",
3+
"compilerOptions": {
4+
"outDir": "dist",
5+
"types": ["@repo/typescript-config/react-library"]
6+
},
7+
"include": ["src"],
8+
"exclude": ["node_modules", "dist"]
9+
}

0 commit comments

Comments
 (0)