Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: controlled popover open on focus #2825

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/components/popover/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,22 @@ export type PopoverPropsType = {

/**
* Determine if hover should affect popover visibility.
* @default true
*/
useHover?: boolean;

/**
* Determine if click should affect popover visibility.
* @default true
*/
useClick?: boolean;

/**
* Determine if focus should affect popover visibility.
* @default true
*/
useFocus?: boolean;

/**
* Only controlled component. Handle Popover open state change.
*/
Expand All @@ -63,6 +71,7 @@ const Popover = ({
id,
useHover,
useClick,
useFocus,
defaultOpen = false,
open,
role,
Expand All @@ -76,6 +85,7 @@ const Popover = ({
onOpenChange,
useHover,
useClick,
useFocus,
role,
});

Expand Down
8 changes: 6 additions & 2 deletions src/components/popover/usePopover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
useClick as useFloatingClick,
useHover as useFloatingHover,
useRole,
useFocus,
useFocus as useFloatingFocus,
offset,
flip,
arrow,
Expand All @@ -29,6 +29,7 @@ interface UsePopoverPropTypes {
open?: boolean;
useHover?: boolean;
useClick?: boolean;
useFocus?: boolean;
role?: PopoverRole;
onOpenChange?: (arg0: boolean) => void;
}
Expand All @@ -40,6 +41,7 @@ const usePopover = ({
open,
useHover = true,
useClick = true,
useFocus = true,
role = 'dialog',
onOpenChange,
}: UsePopoverPropTypes) => {
Expand Down Expand Up @@ -130,7 +132,9 @@ const usePopover = ({
blockPointerEvents: true,
}),
});
const focus = useFocus(data.context);
const focus = useFloatingFocus(data.context, {
enabled: useFocus,
});
const click = useFloatingClick(data.context, {
enabled: useClick,
});
Expand Down
Loading