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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Then open `http://localhost:8000`.
| `classNames` | `Partial<Record<SemanticName, string>>` | - | Semantic class names for root, arrow, and container nodes. |
| `defaultVisible` | boolean | - | Initial uncontrolled visible state. |
| `destroyOnHidden` | boolean | false | Destroy popup DOM when hidden. |
| `disabled` | boolean | false | Temporarily hide tooltip while preserving visible state. |
| `fresh` | boolean | - | Keep popup content fresh when closed. |
| `getTooltipContainer` | `(node: HTMLElement) => HTMLElement` | - | Resolve popup container. |
| `id` | string | generated id | Tooltip id used for accessibility. |
Expand Down
12 changes: 12 additions & 0 deletions docs/demo/disabled.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Disabled
order: 9
---

Hover the button to show the Tooltip. Click it to toggle `disabled`.

```jsx
import DisabledDemo from '../examples/disabled';

export default () => <DisabledDemo />;
```
19 changes: 19 additions & 0 deletions docs/examples/disabled.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React, { useState } from 'react';
import '../../assets/bootstrap.less';
import Tooltip from '../../src';

const DisabledDemo = () => {
const [disabled, setDisabled] = useState(false);

return (
<div style={{ margin: 100 }}>
<Tooltip disabled={disabled} overlay="Tooltip content" placement="top">
<button type="button" onClick={() => setDisabled((value) => !value)}>
{disabled ? 'Enable Tooltip' : 'Disable Tooltip'}
</button>
</Tooltip>
</div>
);
};

export default DisabledDemo;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"prepare": "husky"
},
"dependencies": {
"@rc-component/trigger": "^3.7.1",
"@rc-component/trigger": "^3.10.0",
"@rc-component/util": "^1.11.1",
"clsx": "^2.1.1"
},
Expand Down
1 change: 1 addition & 0 deletions src/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface TooltipProps extends Pick<
TriggerProps,
| 'onPopupAlign'
| 'builtinPlacements'
| 'disabled'
| 'fresh'
| 'mouseLeaveDelay'
| 'mouseEnterDelay'
Expand Down
26 changes: 26 additions & 0 deletions tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,32 @@ describe('rc-tooltip', () => {
expect(container.querySelector('.x-content')).toBeTruthy();
});

it('temporarily hides while disabled and restores without mouse leave', () => {
const App = () => {
const [disabled, setDisabled] = React.useState(false);

return (
<Tooltip disabled={disabled} overlay="Tooltip content">
<button type="button" onClick={() => setDisabled((value) => !value)}>
Toggle disabled
</button>
</Tooltip>
);
};

const { container } = render(<App />);
const button = container.querySelector('button');

fireEvent.mouseEnter(button);
expect(container.querySelector('.rc-tooltip')).not.toHaveClass('rc-tooltip-hidden');

fireEvent.click(button);
expect(container.querySelector('.rc-tooltip')).toHaveClass('rc-tooltip-hidden');

fireEvent.click(button);
expect(container.querySelector('.rc-tooltip')).not.toHaveClass('rc-tooltip-hidden');
Comment on lines +323 to +330

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To verify that the accessibility attributes (aria-describedby) are correctly managed when the tooltip is disabled, we should add assertions for aria-describedby in this test case.

Suggested change
fireEvent.mouseEnter(button);
expect(container.querySelector('.rc-tooltip')).not.toHaveClass('rc-tooltip-hidden');
fireEvent.click(button);
expect(container.querySelector('.rc-tooltip')).toHaveClass('rc-tooltip-hidden');
fireEvent.click(button);
expect(container.querySelector('.rc-tooltip')).not.toHaveClass('rc-tooltip-hidden');
fireEvent.mouseEnter(button);
expect(container.querySelector('.rc-tooltip')).not.toHaveClass('rc-tooltip-hidden');
expect(button).toHaveAttribute('aria-describedby');
fireEvent.click(button);
expect(container.querySelector('.rc-tooltip')).toHaveClass('rc-tooltip-hidden');
expect(button).not.toHaveAttribute('aria-describedby');
fireEvent.click(button);
expect(container.querySelector('.rc-tooltip')).not.toHaveClass('rc-tooltip-hidden');
expect(button).toHaveAttribute('aria-describedby');

});

it('ref support nativeElement', () => {
const nodeRef = React.createRef<TooltipRef>();

Expand Down
Loading