Skip to content

Commit 28cdb2d

Browse files
ElliotLuke Bowerman
andauthored
Tooltip: Preserve hover style when cursor moves to tooltip text (#1017)
* Tooltip now clones child with hover class if tooltip is Open * Added a note to docs * Clarified language in docs * Fixed playground index.tsx Co-authored-by: Luke Bowerman <[email protected]>
1 parent 5934ad1 commit 28cdb2d

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

packages/components/src/Tooltip/Tooltip.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ export function useTooltip({
234234

235235
return {
236236
'aria-describedby': guaranteedId,
237+
isOpen,
237238
onBlur: handleClose,
238239
onFocus: handleOpen,
239240
onMouseOut: handleMouseOut,
@@ -254,7 +255,8 @@ export const Tooltip: FC<TooltipProps> = ({ children, ...props }) => {
254255
const tooltipProps = useTooltip(props)
255256

256257
const tooltipPropsLabeled = {
257-
...omit(tooltipProps, ['tooltip', 'popperInstanceRef']),
258+
...omit(tooltipProps, ['tooltip', 'popperInstanceRef', 'isOpen']),
259+
className: tooltipProps.isOpen ? 'hover' : '',
258260
}
259261

260262
let target = children

packages/playground/src/index.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,21 @@
2525
*/
2626
import React from 'react'
2727
import { render } from 'react-dom'
28-
import { ComponentsProvider } from '@looker/components'
29-
import { ButtonSetDemo } from './Actions/ButtonSetDemo'
28+
import { ComponentsProvider, Tooltip, Button } from '@looker/components'
3029

3130
const App = () => {
3231
return (
3332
<ComponentsProvider>
34-
<ButtonSetDemo />
33+
<div>
34+
<Tooltip content="Hello Darkness My Old Friend" placement="right">
35+
<Button>Hello World</Button>
36+
</Tooltip>
37+
</div>
38+
<div>
39+
<Tooltip content="Hello Darkness My Old Friend" placement="right">
40+
{(props) => <Button {...props}>Hello World</Button>}
41+
</Tooltip>
42+
</div>
3543
</ComponentsProvider>
3644
)
3745
}

packages/www/src/documentation/components/overlays/tooltip.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ A simple Tooltip component with out of the box styles and behavior.
2929
</Tooltip>
3030
```
3131
32+
## Tooltip Placement
33+
3234
Tooltip allows you to specify where it should appear in relation to the target element. It accepts the following values:
3335
3436
1. `auto`
@@ -92,4 +94,8 @@ If you need to be very specific
9294
</Tooltip>
9395
```
9496
95-
## Tooltip Placement
97+
## Tooltip passes a "hover" class
98+
99+
In both the regular and "Render Prop" styles, `Tooltip` will pass a class named `hover` to its child element (or function) when the `Tooltip` is open.
100+
101+
This will preserve any hover styling when the cursor is on the tooltip text and off of the trigger element itself.

0 commit comments

Comments
 (0)