Skip to content

Commit 9ae7583

Browse files
committed
Add prop types for FocusGuard
1 parent 4ee4df2 commit 9ae7583

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

.changeset/sad-trees-slide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@radix-ui/react-focus-guards': patch
3+
---
4+
5+
Add prop types for `FocusGuard`

apps/storybook/stories/dismissable-layer.stories.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,14 +484,13 @@ type DummyDialogProps = {
484484

485485
function DummyDialog({ children, openLabel = 'Open', closeLabel = 'Close' }: DummyDialogProps) {
486486
const [open, setOpen] = React.useState(false);
487-
const buttonRef = React.useRef<HTMLButtonElement>(null);
488487
return (
489488
<>
490-
<button type="button" ref={buttonRef} onClick={() => setOpen((prevOpen) => !prevOpen)}>
489+
<button type="button" onClick={() => setOpen((prevOpen) => !prevOpen)}>
491490
{openLabel}
492491
</button>
493492
{open ? (
494-
<FocusGuards.Root domRef={buttonRef}>
493+
<FocusGuards.Root>
495494
<Portal.Root asChild>
496495
<div
497496
style={{

packages/react/focus-guards/src/focus-guards.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import * as React from 'react';
33
/** Number of components which have requested interest to have focus guards */
44
let count = 0;
55

6-
function FocusGuards(props: any) {
6+
interface FocusGuardsProps {
7+
children?: React.ReactNode;
8+
}
9+
10+
function FocusGuards(props: FocusGuardsProps) {
711
useFocusGuards();
812
return props.children;
913
}
@@ -13,6 +17,7 @@ function FocusGuards(props: any) {
1317
* to ensure `focusin` & `focusout` events can be caught consistently.
1418
*/
1519
function useFocusGuards() {
20+
/* eslint-disable no-restricted-globals */
1621
React.useEffect(() => {
1722
const edgeGuards = document.querySelectorAll('[data-radix-focus-guard]');
1823
document.body.insertAdjacentElement('afterbegin', edgeGuards[0] ?? createFocusGuard());
@@ -26,9 +31,11 @@ function useFocusGuards() {
2631
count--;
2732
};
2833
}, []);
34+
/* eslint-enable no-restricted-globals */
2935
}
3036

3137
function createFocusGuard() {
38+
// eslint-disable-next-line no-restricted-globals
3239
const element = document.createElement('span');
3340
element.setAttribute('data-radix-focus-guard', '');
3441
element.tabIndex = 0;
@@ -39,12 +46,10 @@ function createFocusGuard() {
3946
return element;
4047
}
4148

42-
const Root = FocusGuards;
43-
4449
export {
4550
FocusGuards,
4651
//
47-
Root,
52+
FocusGuards as Root,
4853
//
4954
useFocusGuards,
5055
};

0 commit comments

Comments
 (0)