Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/swift-guests-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/popover": minor
---

Add `updatePositionDeps` prop to popover component
5 changes: 3 additions & 2 deletions apps/docs/content/docs/components/popover.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ You can customize the `Popover` component by passing custom Tailwind CSS classes
| shouldCloseOnBlur | `boolean` | Whether the popover should close when focus is lost or moves outside it. | `false` |
| motionProps | [MotionProps](#motion-props) | The props to modify the framer motion animation. Use the `variants` API to create your own animation. | |
| portalContainer | `HTMLElement` | The container element in which the overlay portal will be placed. | `document.body` |
| updatePositionDeps | `any[]` | The dependencies to force the popover position update. | `[]` |
| triggerRef | `RefObject<HTMLElement>` | The ref for the element which the popover positions itself with respect to. | - |
| scrollRef | `RefObject<HTMLElement>` | A ref for the scrollable region within the popover. | `overlayRef` |
| disableAnimation | `boolean` | Whether the popover is animated. | `false` |
Expand All @@ -178,8 +179,8 @@ You can customize the `Popover` component by passing custom Tailwind CSS classes

### PopoverTrigger Props

| Attribute | Type | Description | Default |
| ---------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| Attribute | Type | Description | Default |
| ---------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| children\* | `ReactNode` | The popover trigger component, ensure the children passed is focusable. Users can tab to it using their keyboard, and it can take a ref. It is critical for accessibility. | - |

<Spacer y={2} />
Expand Down
1 change: 1 addition & 0 deletions packages/components/popover/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@nextui-org/button": "workspace:*",
"@nextui-org/shared-utils": "workspace:*",
"@nextui-org/react-utils": "workspace:*",
"@nextui-org/use-safe-layout-effect": "workspace:*",
"@react-aria/dialog": "^3.5.7",
"@react-aria/interactions": "^3.19.1",
"@react-aria/overlays": "^3.18.1",
Expand Down
14 changes: 14 additions & 0 deletions packages/components/popover/src/use-aria-popover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import {OverlayPlacement, ariaHideOutside, toReactAriaPlacement} from "@nextui-org/aria-utils";
import {OverlayTriggerState} from "@react-stately/overlays";
import {mergeProps} from "@react-aria/utils";
import {useSafeLayoutEffect} from "@nextui-org/use-safe-layout-effect";

export interface Props {
/**
Expand All @@ -26,6 +27,11 @@ export interface Props {
* @default popoverRef
*/
scrollRef?: RefObject<HTMLElement>;
/**
* List of dependencies to update the position of the popover.
* @default []
*/
updatePositionDeps?: any[];
}

export type ReactAriaPopoverProps = Props & Omit<AriaPopoverProps, "placement"> & AriaOverlayProps;
Expand Down Expand Up @@ -54,6 +60,7 @@ export function useReactAriaPopover(
shouldCloseOnInteractOutside,
isNonModal: isNonModalProp,
isKeyboardDismissDisabled,
updatePositionDeps = [],
...otherProps
} = props;

Expand Down Expand Up @@ -82,6 +89,7 @@ export function useReactAriaPopover(
overlayProps: positionProps,
arrowProps,
placement,
updatePosition,
} = useOverlayPosition({
...otherProps,
shouldFlip,
Expand All @@ -97,6 +105,12 @@ export function useReactAriaPopover(
onClose: () => {},
});

useSafeLayoutEffect(() => {
if (!updatePositionDeps.length) return;
// force update position when deps change
updatePosition();
}, updatePositionDeps);

useEffect(() => {
if (state.isOpen && !isNonModal && popoverRef.current) {
return ariaHideOutside([popoverRef.current]);
Expand Down
2 changes: 2 additions & 0 deletions packages/components/popover/src/use-popover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export function usePopover(originalProps: UsePopoverProps) {
isDismissable = true,
shouldCloseOnBlur,
portalContainer,
updatePositionDeps,
placement: placementProp = "top",
triggerType = "dialog",
showArrow = false,
Expand Down Expand Up @@ -151,6 +152,7 @@ export function usePopover(originalProps: UsePopoverProps) {
crossOffset,
shouldFlip,
containerPadding,
updatePositionDeps,
isKeyboardDismissDisabled,
shouldCloseOnInteractOutside,
},
Expand Down
Loading