Skip to content

Commit b31ffba

Browse files
feat(DefinitionTooltip): add openOnHover prop (#12288)
* feat(DefinitionTooltip): add ability to open on hover * test(snapshot): update snapshots Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 2fd3f86 commit b31ffba

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2492,6 +2492,12 @@ Map {
24922492
"bottom",
24932493
"bottom-left",
24942494
"bottom-right",
2495+
"left",
2496+
"left-bottom",
2497+
"left-top",
2498+
"right",
2499+
"right-bottom",
2500+
"right-top",
24952501
],
24962502
],
24972503
"type": "oneOf",
@@ -2513,6 +2519,9 @@ Map {
25132519
"id": Object {
25142520
"type": "string",
25152521
},
2522+
"openOnHover": Object {
2523+
"type": "bool",
2524+
},
25162525
"tooltipText": [Function],
25172526
"triggerClassName": Object {
25182527
"type": "string",

packages/react/src/components/Tooltip/next/DefinitionTooltip.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function DefinitionTooltip({
2121
definition,
2222
defaultOpen = false,
2323
id,
24+
openOnHover,
2425
tooltipText,
2526
triggerClassName,
2627
...rest
@@ -45,6 +46,9 @@ function DefinitionTooltip({
4546
onMouseLeave={() => {
4647
setOpen(false);
4748
}}
49+
onMouseEnter={() => {
50+
openOnHover ? setOpen(true) : null;
51+
}}
4852
open={isOpen}>
4953
<button
5054
{...rest}
@@ -82,6 +86,14 @@ DefinitionTooltip.propTypes = {
8286
'bottom',
8387
'bottom-left',
8488
'bottom-right',
89+
90+
'left',
91+
'left-bottom',
92+
'left-top',
93+
94+
'right',
95+
'right-bottom',
96+
'right-top',
8597
]),
8698

8799
/**
@@ -111,6 +123,11 @@ DefinitionTooltip.propTypes = {
111123
*/
112124
id: PropTypes.string,
113125

126+
/**
127+
* Specifies whether or not the `DefinitionTooltip` should open on hover or not
128+
*/
129+
openOnHover: PropTypes.bool,
130+
114131
/**
115132
* [Deprecated in v11] Please use the `definition` prop instead.
116133
*

packages/react/src/components/Tooltip/next/DefinitionTooltip.stories.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,10 @@ export const Default = () => {
5959
};
6060

6161
const PlaygroundStory = (props) => {
62-
const { align, defaultOpen, definition } = props;
6362
return (
6463
<p>
6564
This sentence contains a{' '}
66-
<DefinitionTooltip
67-
align={align}
68-
defaultOpen={defaultOpen}
69-
definition={definition}>
70-
definition tooltip
71-
</DefinitionTooltip>
72-
.
65+
<DefinitionTooltip {...props}>definition tooltip</DefinitionTooltip>.
7366
</p>
7467
);
7568
};
@@ -87,6 +80,14 @@ Playground.argTypes = {
8780
'bottom',
8881
'bottom-left',
8982
'bottom-right',
83+
84+
'left',
85+
'left-bottom',
86+
'left-top',
87+
88+
'right',
89+
'right-bottom',
90+
'right-top',
9091
],
9192
control: {
9293
type: 'select',
@@ -101,4 +102,10 @@ Playground.argTypes = {
101102
},
102103
defaultValue: 'Example definition',
103104
},
105+
openOnHover: {
106+
control: {
107+
type: 'boolean',
108+
},
109+
defaultValue: false,
110+
},
104111
};

0 commit comments

Comments
 (0)