Skip to content

Commit 7ea07f7

Browse files
author
Elliot
authored
Fixed child class replacement bug (#1033)
* Fixed child class replacement bug * CHANGELOG updated * Added hover class to renderProps method * Removed auto passing of hover class for renderProps method * Added passed-in className based on isOpen state to render props method
1 parent 3c5547f commit 7ea07f7

File tree

3 files changed

+48
-16
lines changed

3 files changed

+48
-16
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
- Jest no longer requires artifact build before being run
1515

16+
### Fixed
17+
18+
- `Tooltip` appends `hover` class if tooltip is open rather and doesn't replace given `className` prop value
19+
1620
## [0.8.4]
1721

1822
### Added

packages/components/src/Tooltip/Tooltip.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export const CustomizableTooltipAttributes: CustomizableAttributes = {}
110110

111111
type TooltipRenderProp = (tooltipProps: {
112112
'aria-describedby': string
113+
className?: string
113114
onBlur: () => void
114115
onFocus: () => void
115116
onMouseOut: (event: React.MouseEvent<Element, MouseEvent>) => void
@@ -254,17 +255,24 @@ function isRenderProp(
254255
export const Tooltip: FC<TooltipProps> = ({ children, ...props }) => {
255256
const tooltipProps = useTooltip(props)
256257

258+
let target = children
259+
257260
const tooltipPropsLabeled = {
258261
...omit(tooltipProps, ['tooltip', 'popperInstanceRef', 'isOpen']),
259-
className: tooltipProps.isOpen ? 'hover' : '',
260262
}
261263

262-
let target = children
263-
264264
if (isValidElement(children)) {
265-
target = cloneElement(children, { ...tooltipPropsLabeled })
265+
target = cloneElement(children, {
266+
...tooltipPropsLabeled,
267+
className: tooltipProps.isOpen
268+
? `${children.props.className} hover`
269+
: children.props.className,
270+
})
266271
} else if (isRenderProp(children)) {
267-
target = children(tooltipPropsLabeled)
272+
target = children({
273+
...tooltipPropsLabeled,
274+
className: tooltipProps.isOpen ? 'hover' : '',
275+
})
268276
} else {
269277
// eslint-disable-next-line no-console
270278
console.warn(

packages/playground/src/index.tsx

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,41 @@
2525
*/
2626
import React from 'react'
2727
import { render } from 'react-dom'
28-
import { ComponentsProvider, Flex, Icon } from '@looker/components'
28+
import { ComponentsProvider, ButtonOutline, Tooltip } from '@looker/components'
2929

3030
const App = () => {
3131
return (
3232
<ComponentsProvider>
33-
<Flex alignItems="center" justifyContent="center">
34-
<Icon name="GearOutline" size="xxsmall" />
35-
<Icon name="GearOutline" size="xsmall" />
36-
<Icon name="GearOutline" size="small" />
37-
<Icon name="GearOutline" size="medium" />
38-
<Icon name="GearOutline" />
39-
<Icon name="GearOutline" size="large" />
40-
<Icon name="GearOutline" size="78px" />
41-
<Icon name="GearOutline" size="90px" />
42-
</Flex>
33+
<Tooltip
34+
width="20rem"
35+
placement="right"
36+
textAlign="left"
37+
content={
38+
<>
39+
This is a tooltip with quite a bit of text. It's probably not ideal
40+
to have this much text in a Tooltip. Perhaps you should link to
41+
another document
42+
</>
43+
}
44+
>
45+
<ButtonOutline>Tooltip with lots of text</ButtonOutline>
46+
</Tooltip>
47+
<Tooltip
48+
width="20rem"
49+
placement="right"
50+
textAlign="left"
51+
content={
52+
<>
53+
This is a tooltip with quite a bit of text. It's probably not ideal
54+
to have this much text in a Tooltip. Perhaps you should link to
55+
another document
56+
</>
57+
}
58+
>
59+
<ButtonOutline className="hover">
60+
Tooltip with lots of text
61+
</ButtonOutline>
62+
</Tooltip>
4363
</ComponentsProvider>
4464
)
4565
}

0 commit comments

Comments
 (0)