Skip to content

Commit 6dbce3d

Browse files
committed
feat: semantic add uniqueBody
1 parent a00cd1a commit 6dbce3d

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"test": "rc-test"
4242
},
4343
"dependencies": {
44-
"@rc-component/trigger": "^3.6.4",
44+
"@rc-component/trigger": "^3.6.7",
4545
"@rc-component/util": "^1.3.0",
4646
"classnames": "^2.3.1"
4747
},

src/Tooltip.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useImperativeHandle, useRef } from 'react';
88
import { placements } from './placements';
99
import Popup from './Popup';
1010

11-
export type SemanticName = 'root' | 'arrow' | 'body';
11+
export type SemanticName = 'root' | 'arrow' | 'body' | 'uniqueBody';
1212

1313
export interface TooltipProps
1414
extends Pick<
@@ -154,6 +154,8 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
154154
popupStyle={styles?.root}
155155
mouseEnterDelay={mouseEnterDelay}
156156
arrow={mergedArrow}
157+
uniqueBgClassName={classNames?.uniqueBody}
158+
uniqueBgStyle={styles?.uniqueBody}
157159
{...extraProps}
158160
>
159161
{getChildren()}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
import Trigger from '@rc-component/trigger/lib/mock';
1+
import Trigger, { UniqueProvider } from '@rc-component/trigger/lib/mock';
22

33
export default Trigger;
4+
export { UniqueProvider };

tests/index.test.tsx

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { UniqueProvider } from '@rc-component/trigger';
12
import { act, fireEvent, render } from '@testing-library/react';
23
import React from 'react';
34
import Tooltip, { type TooltipRef } from '../src';
@@ -59,8 +60,6 @@ describe('rc-tooltip', () => {
5960
verifyContent(container, 'Tooltip content');
6061
});
6162

62-
63-
6463
it('access of ref', () => {
6564
const domRef = React.createRef<TooltipRef>();
6665
render(
@@ -353,12 +352,7 @@ describe('rc-tooltip', () => {
353352
};
354353

355354
const { container } = render(
356-
<Tooltip
357-
styles={customStyles}
358-
overlay={<div>Tooltip content</div>}
359-
visible
360-
showArrow
361-
>
355+
<Tooltip styles={customStyles} overlay={<div>Tooltip content</div>} visible showArrow>
362356
<button>Trigger</button>
363357
</Tooltip>,
364358
);
@@ -439,12 +433,36 @@ describe('rc-tooltip', () => {
439433
// Verify partial configuration takes effect
440434
expect(tooltipElement).toHaveStyle({ backgroundColor: 'blue' });
441435
expect(tooltipBodyElement).toHaveClass('custom-body');
442-
436+
443437
// Verify that unconfigured elements don't have custom class names or styles
444438
expect(tooltipElement).not.toHaveClass('custom-root');
445439
expect(tooltipArrowElement).not.toHaveClass('custom-arrow');
446440
});
447441

442+
it('should pass uniqueBody to Trigger as uniqueBgClassName and uniqueBgStyle', () => {
443+
// Test that the component renders without errors when uniqueBody is provided
444+
render(
445+
<UniqueProvider>
446+
<Tooltip
447+
classNames={{ uniqueBody: 'unique-body-class' }}
448+
styles={{ uniqueBody: { color: 'red' } }}
449+
overlay={<div>Tooltip content</div>}
450+
visible
451+
unique
452+
>
453+
<button>Trigger</button>
454+
</Tooltip>
455+
</UniqueProvider>,
456+
);
457+
458+
console.log(document.body.innerHTML);
459+
460+
// Test that uniqueBody doesn't break the normal tooltip functionality
461+
expect(document.querySelector('.unique-body-class')).toHaveStyle({
462+
color: 'red',
463+
});
464+
});
465+
448466
it('should not break when showArrow is false', () => {
449467
const customClassNames = {
450468
root: 'custom-root',
@@ -476,7 +494,7 @@ describe('rc-tooltip', () => {
476494

477495
// Verify when arrow is not shown
478496
expect(tooltipArrowElement).toBeFalsy();
479-
497+
480498
// Other styles still take effect
481499
expect(tooltipElement).toHaveClass('custom-root');
482500
expect(tooltipElement).toHaveStyle({ backgroundColor: 'blue' });

0 commit comments

Comments
 (0)