Skip to content

Commit b83963f

Browse files
committed
feat: uniqueBgStyle
1 parent 0d874e5 commit b83963f

File tree

5 files changed

+82
-2
lines changed

5 files changed

+82
-2
lines changed

src/UniqueProvider/FloatBg.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface FloatBgProps {
1818
popupSize?: { width: number; height: number };
1919
motion?: CSSMotionProps;
2020
uniqueBgClassName?: string;
21+
uniqueBgStyle?: React.CSSProperties;
2122
}
2223

2324
const FloatBg = (props: FloatBgProps) => {
@@ -34,6 +35,7 @@ const FloatBg = (props: FloatBgProps) => {
3435
popupSize,
3536
motion,
3637
uniqueBgClassName,
38+
uniqueBgStyle,
3739
} = props;
3840

3941
const floatBgCls = `${prefixCls}-float-bg`;
@@ -85,6 +87,7 @@ const FloatBg = (props: FloatBgProps) => {
8587
...offsetStyle,
8688
...sizeStyle,
8789
...motionStyle,
90+
...uniqueBgStyle,
8891
}}
8992
/>
9093
);

src/UniqueProvider/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ const UniqueProvider = ({ children }: UniqueProviderProps) => {
217217
popupSize={popupSize}
218218
motion={options.popupMotion}
219219
uniqueBgClassName={options.uniqueBgClassName}
220+
uniqueBgStyle={options.uniqueBgStyle}
220221
/>
221222
</Popup>
222223
</TriggerContext.Provider>

src/context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface UniqueShowOptions {
2121
prefixCls?: string;
2222
popupClassName?: string;
2323
uniqueBgClassName?: string;
24+
uniqueBgStyle?: React.CSSProperties;
2425
popupStyle?: React.CSSProperties;
2526
popupPlacement?: string;
2627
builtinPlacements?: BuildInPlacements;

src/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ export interface TriggerProps {
100100
popupClassName?: string;
101101
/** Pass to `UniqueProvider` FloatBg */
102102
uniqueBgClassName?: string;
103+
/** Pass to `UniqueProvider` FloatBg */
104+
uniqueBgStyle?: React.CSSProperties;
103105
popupStyle?: React.CSSProperties;
104106
getPopupClassNameFromAlign?: (align: AlignType) => string;
105107
onPopupClick?: React.MouseEventHandler<HTMLDivElement>;
@@ -172,6 +174,7 @@ export function generateTrigger(
172174
popup,
173175
popupClassName,
174176
uniqueBgClassName,
177+
uniqueBgStyle,
175178
popupStyle,
176179

177180
popupPlacement,
@@ -327,6 +330,7 @@ export function generateTrigger(
327330
prefixCls,
328331
popupClassName,
329332
uniqueBgClassName,
333+
uniqueBgStyle,
330334
popupStyle,
331335
popupPlacement,
332336
builtinPlacements,

tests/unique.test.tsx

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,89 @@ describe('Trigger.Unique', () => {
161161
popup={<strong className="x-content">tooltip</strong>}
162162
unique
163163
uniqueBgClassName="custom-bg-class"
164-
popupVisible
165164
>
166165
<div className="target">click me</div>
167166
</Trigger>
168167
</UniqueProvider>,
169168
);
170169

170+
// Initially no popup should be visible
171+
expect(document.querySelector('.rc-trigger-popup')).toBeFalsy();
172+
173+
// Click trigger to show popup
174+
fireEvent.click(container.querySelector('.target'));
171175
await awaitFakeTimer();
172176

177+
// Check that popup exists
178+
const popup = document.querySelector('.rc-trigger-popup');
179+
expect(popup).toBeTruthy();
180+
173181
// Check that FloatBg has the custom background className
174182
const floatBg = document.querySelector('.rc-trigger-popup-float-bg');
175183
expect(floatBg).toBeTruthy();
176-
expect(floatBg).toHaveClass('custom-bg-class');
184+
expect(floatBg.className).toContain('custom-bg-class');
185+
});
186+
187+
it('should apply uniqueBgStyle to FloatBg component', async () => {
188+
const { container } = render(
189+
<UniqueProvider>
190+
<Trigger
191+
action={['click']}
192+
popup={<strong className="x-content">tooltip</strong>}
193+
unique
194+
uniqueBgStyle={{ backgroundColor: 'red', border: '1px solid blue' }}
195+
>
196+
<div className="target">click me</div>
197+
</Trigger>
198+
</UniqueProvider>,
199+
);
200+
201+
// Initially no popup should be visible
202+
expect(document.querySelector('.rc-trigger-popup')).toBeFalsy();
203+
204+
// Click trigger to show popup
205+
fireEvent.click(container.querySelector('.target'));
206+
await awaitFakeTimer();
207+
208+
// Check that popup exists
209+
const popup = document.querySelector('.rc-trigger-popup');
210+
expect(popup).toBeTruthy();
211+
212+
// Check that FloatBg has the custom background style
213+
const floatBg = document.querySelector('.rc-trigger-popup-float-bg');
214+
expect(floatBg).toBeTruthy();
215+
const computedStyle = window.getComputedStyle(floatBg);
216+
expect(computedStyle.backgroundColor).toBe('red');
217+
expect(computedStyle.border).toContain('1px solid blue');
218+
});
219+
220+
it('should not apply any additional className to FloatBg when uniqueBgClassName is not provided', async () => {
221+
const { container } = render(
222+
<UniqueProvider>
223+
<Trigger
224+
action={['click']}
225+
popup={<strong className="x-content">tooltip</strong>}
226+
unique
227+
>
228+
<div className="target">click me</div>
229+
</Trigger>
230+
</UniqueProvider>,
231+
);
232+
233+
// Initially no popup should be visible
234+
expect(document.querySelector('.rc-trigger-popup')).toBeFalsy();
235+
236+
// Click trigger to show popup
237+
fireEvent.click(container.querySelector('.target'));
238+
await awaitFakeTimer();
239+
240+
// Check that popup exists
241+
const popup = document.querySelector('.rc-trigger-popup');
242+
expect(popup).toBeTruthy();
243+
244+
// Check that FloatBg exists but does not have custom background className
245+
const floatBg = document.querySelector('.rc-trigger-popup-float-bg');
246+
expect(floatBg).toBeTruthy();
247+
expect(floatBg.className).not.toContain('undefined');
177248
});
178249
});

0 commit comments

Comments
 (0)