From 3fa49ac7f87e2dfd125a483844ac284cad1b2d9a Mon Sep 17 00:00:00 2001
From: Ryo Matsukawa <76232929+ryo-manba@users.noreply.github.com>
Date: Mon, 30 Dec 2024 15:05:42 +0900
Subject: [PATCH 1/3] fix(popover): correct initial animation direction to
match fallback placement
---
.../components/popover/src/use-popover.ts | 22 ++++----------
.../popover/stories/popover.stories.tsx | 30 +++++++++++++++++--
2 files changed, 33 insertions(+), 19 deletions(-)
diff --git a/packages/components/popover/src/use-popover.ts b/packages/components/popover/src/use-popover.ts
index bc12cb14f4..22aa39dc3e 100644
--- a/packages/components/popover/src/use-popover.ts
+++ b/packages/components/popover/src/use-popover.ts
@@ -14,7 +14,7 @@ import {
PropGetter,
useProviderContext,
} from "@nextui-org/system";
-import {getArrowPlacement, getShouldUseAxisPlacement} from "@nextui-org/aria-utils";
+import {getArrowPlacement} from "@nextui-org/aria-utils";
import {popover} from "@nextui-org/theme";
import {mergeProps, mergeRefs} from "@react-aria/utils";
import {clsx, dataAttr, objectToDeps} from "@nextui-org/shared-utils";
@@ -150,11 +150,7 @@ export function usePopover(originalProps: UsePopoverProps) {
const state = stateProp || innerState;
- const {
- popoverProps,
- underlayProps,
- placement: ariaPlacement,
- } = useReactAriaPopover(
+ const {popoverProps, underlayProps, placement} = useReactAriaPopover(
{
triggerRef,
isNonModal,
@@ -208,7 +204,7 @@ export function usePopover(originalProps: UsePopoverProps) {
"data-focus": dataAttr(isFocused),
"data-arrow": dataAttr(showArrow),
"data-focus-visible": dataAttr(isFocusVisible),
- "data-placement": getArrowPlacement(ariaPlacement || "top", placementProp),
+ "data-placement": getArrowPlacement(placement || "top", placementProp),
...mergeProps(focusProps, dialogPropsProp, props),
className: slots.base({class: clsx(baseStyles)}),
style: {
@@ -222,18 +218,10 @@ export function usePopover(originalProps: UsePopoverProps) {
"data-slot": "content",
"data-open": dataAttr(state.isOpen),
"data-arrow": dataAttr(showArrow),
- "data-placement": getArrowPlacement(ariaPlacement || "top", placementProp),
+ "data-placement": getArrowPlacement(placement || "top", placementProp),
className: slots.content({class: clsx(classNames?.content, props.className)}),
}),
- [slots, state.isOpen, showArrow, ariaPlacement, placementProp, classNames],
- );
-
- const placement = useMemo(
- () =>
- getShouldUseAxisPlacement(ariaPlacement || "top", placementProp)
- ? ariaPlacement || placementProp
- : placementProp,
- [ariaPlacement, placementProp],
+ [slots, state.isOpen, showArrow, placement, placementProp, classNames],
);
const onPress = useCallback(
diff --git a/packages/components/popover/stories/popover.stories.tsx b/packages/components/popover/stories/popover.stories.tsx
index 3df9aae279..1edfb00a5c 100644
--- a/packages/components/popover/stories/popover.stories.tsx
+++ b/packages/components/popover/stories/popover.stories.tsx
@@ -127,11 +127,11 @@ const content = (
);
-const Template = (args: PopoverProps) => {
+const Template = ({label = "Open Popover", ...args}: PopoverProps & {label: string}) => {
return (