Skip to content

Commit fa5bf88

Browse files
committed
chore: adjust align logic
1 parent bbbb755 commit fa5bf88

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

src/UniqueProvider/UniqueBody.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ const UniqueBody = (props: UniqueBodyProps) => {
5656
offsetY,
5757
);
5858

59+
// Cache for offsetStyle when ready is true
60+
const cachedOffsetStyleRef = React.useRef(offsetStyle);
61+
62+
// Update cached offset style when ready is true
63+
if (ready) {
64+
cachedOffsetStyleRef.current = offsetStyle;
65+
}
66+
5967
// Apply popup size if available
6068
const sizeStyle: React.CSSProperties = {};
6169
if (popupSize) {
@@ -85,14 +93,16 @@ const UniqueBody = (props: UniqueBodyProps) => {
8593
return (
8694
<div
8795
className={cls}
88-
style={{
89-
'--arrow-x': `${arrowPos?.x || 0}px`,
90-
'--arrow-y': `${arrowPos?.y || 0}px`,
91-
...offsetStyle,
92-
...sizeStyle,
93-
...motionStyle,
94-
...uniqueBgStyle,
95-
} as React.CSSProperties}
96+
style={
97+
{
98+
'--arrow-x': `${arrowPos?.x || 0}px`,
99+
'--arrow-y': `${arrowPos?.y || 0}px`,
100+
...cachedOffsetStyleRef.current,
101+
...sizeStyle,
102+
...motionStyle,
103+
...uniqueBgStyle,
104+
} as React.CSSProperties
105+
}
96106
/>
97107
);
98108
}}

src/UniqueProvider/index.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,35 +105,35 @@ const UniqueProvider = ({ children, postTriggerProps }: UniqueProviderProps) =>
105105
] = useAlign(
106106
open,
107107
popupEle,
108-
options?.target,
109-
options?.popupPlacement,
110-
options?.builtinPlacements || {},
111-
options?.popupAlign,
108+
mergedOptions?.target,
109+
mergedOptions?.popupPlacement,
110+
mergedOptions?.builtinPlacements || {},
111+
mergedOptions?.popupAlign,
112112
undefined, // onPopupAlign
113113
false, // isMobile
114114
);
115115

116116
const alignedClassName = React.useMemo(() => {
117-
if (!options) {
117+
if (!mergedOptions) {
118118
return '';
119119
}
120120

121121
const baseClassName = getAlignPopupClassName(
122-
options.builtinPlacements || {},
123-
options.prefixCls || '',
122+
mergedOptions.builtinPlacements || {},
123+
mergedOptions.prefixCls || '',
124124
alignInfo,
125125
false, // alignPoint is false for UniqueProvider
126126
);
127127

128128
return classNames(
129129
baseClassName,
130-
options.getPopupClassNameFromAlign?.(alignInfo),
130+
mergedOptions.getPopupClassNameFromAlign?.(alignInfo),
131131
);
132132
}, [
133133
alignInfo,
134-
options?.getPopupClassNameFromAlign,
135-
options?.builtinPlacements,
136-
options?.prefixCls,
134+
mergedOptions?.getPopupClassNameFromAlign,
135+
mergedOptions?.builtinPlacements,
136+
mergedOptions?.prefixCls,
137137
]);
138138

139139
const contextValue = React.useMemo<UniqueContextProps>(
@@ -171,7 +171,7 @@ const UniqueProvider = ({ children, postTriggerProps }: UniqueProviderProps) =>
171171
return (
172172
<UniqueContext.Provider value={contextValue}>
173173
{children}
174-
{options && (
174+
{mergedOptions && (
175175
<TriggerContext.Provider value={triggerContextValue}>
176176
<Popup
177177
ref={setPopupRef}

0 commit comments

Comments
 (0)