Skip to content

Commit abd0665

Browse files
fix: controlled popover open on focus (#2825)
1 parent fd87a91 commit abd0665

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/components/popover/Popover.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,22 @@ export type PopoverPropsType = {
4040

4141
/**
4242
* Determine if hover should affect popover visibility.
43+
* @default true
4344
*/
4445
useHover?: boolean;
4546

4647
/**
4748
* Determine if click should affect popover visibility.
49+
* @default true
4850
*/
4951
useClick?: boolean;
5052

53+
/**
54+
* Determine if focus should affect popover visibility.
55+
* @default true
56+
*/
57+
useFocus?: boolean;
58+
5159
/**
5260
* Only controlled component. Handle Popover open state change.
5361
*/
@@ -63,6 +71,7 @@ const Popover = ({
6371
id,
6472
useHover,
6573
useClick,
74+
useFocus,
6675
defaultOpen = false,
6776
open,
6877
role,
@@ -76,6 +85,7 @@ const Popover = ({
7685
onOpenChange,
7786
useHover,
7887
useClick,
88+
useFocus,
7989
role,
8090
});
8191

src/components/popover/usePopover.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
useClick as useFloatingClick,
77
useHover as useFloatingHover,
88
useRole,
9-
useFocus,
9+
useFocus as useFloatingFocus,
1010
offset,
1111
flip,
1212
arrow,
@@ -29,6 +29,7 @@ interface UsePopoverPropTypes {
2929
open?: boolean;
3030
useHover?: boolean;
3131
useClick?: boolean;
32+
useFocus?: boolean;
3233
role?: PopoverRole;
3334
onOpenChange?: (arg0: boolean) => void;
3435
}
@@ -40,6 +41,7 @@ const usePopover = ({
4041
open,
4142
useHover = true,
4243
useClick = true,
44+
useFocus = true,
4345
role = 'dialog',
4446
onOpenChange,
4547
}: UsePopoverPropTypes) => {
@@ -130,7 +132,9 @@ const usePopover = ({
130132
blockPointerEvents: true,
131133
}),
132134
});
133-
const focus = useFocus(data.context);
135+
const focus = useFloatingFocus(data.context, {
136+
enabled: useFocus,
137+
});
134138
const click = useFloatingClick(data.context, {
135139
enabled: useClick,
136140
});

0 commit comments

Comments
 (0)