Skip to content

Commit dfce57d

Browse files
author
Luke Bowerman
authored
fix(HoverDisclosure): Remove strategy prop, add placeholderWidth (#2510)
1 parent d57e165 commit dfce57d

File tree

8 files changed

+32
-32
lines changed

8 files changed

+32
-32
lines changed

packages/components/src/List/ListItem.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ describe('ListItem', () => {
124124

125125
test('renders icon', () => {
126126
renderWithTheme(<ListItem icon={<Science />}>Icon</ListItem>)
127-
expect(screen.getByText('Icon')).toBeVisible()
127+
expect(screen.getByText('Icon')).toBeInTheDocument()
128128
})
129129

130130
test('renders artwork', () => {
@@ -266,9 +266,9 @@ describe('ListItem', () => {
266266
</ListItem>
267267
)
268268

269-
expect(screen.queryByText('Detail')).not.toBeVisible()
269+
expect(screen.queryByText('Detail')).not.toBeInTheDocument()
270270
fireEvent.mouseEnter(screen.getByText('Label'), { bubbles: true })
271-
expect(screen.queryByText('Detail')).toBeVisible()
271+
expect(screen.queryByText('Detail')).toBeInTheDocument()
272272
})
273273

274274
test('onKeyUp callback functions', () => {

packages/components/src/List/ListItem.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,13 @@ const ListItemInternal = forwardRef(
233233
</Wrapper>
234234
)
235235

236-
const { accessory, content, hoverDisclosure, padding } = getDetailOptions(
237-
detail
238-
)
236+
const {
237+
accessory,
238+
content,
239+
hoverDisclosure,
240+
padding,
241+
width,
242+
} = getDetailOptions(detail)
239243

240244
const wrapperRef = useRef<HTMLLIElement | HTMLDivElement>(null)
241245
const actualRef = useForkedRef(wrapperRef, ref)
@@ -252,7 +256,7 @@ const ListItemInternal = forwardRef(
252256
})
253257

254258
const renderedDetail = detail && (
255-
<HoverDisclosure visible={!hoverDisclosure}>
259+
<HoverDisclosure width={width} visible={!hoverDisclosure}>
256260
<ListItemDetail
257261
pl={padding ? 'xsmall' : '0'}
258262
pr={accessory && padding ? itemDimensions.px : '0'}

packages/components/src/List/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import { FontSizes, LineHeights, SpacingSizes } from '@looker/design-tokens'
2828
import { ReactNode } from 'react'
2929
import { IconSize } from '../Icon'
30+
import { HoverDisclosureProps } from '../utils/HoverDisclosure'
3031

3132
export type DensityRamp = -3 | -2 | -1 | 0 | 1
3233

@@ -158,7 +159,7 @@ export type ListItemStatefulProps = {
158159
selected?: boolean
159160
}
160161

161-
interface DetailOptions {
162+
interface DetailOptions extends Pick<HoverDisclosureProps, 'width'> {
162163
/**
163164
* If true, the detail will appear outside of the item's grey background on hover
164165
* In addition, if true, events originating from the detail will not bubble to the item's handlers

packages/components/src/List/utils/getDetailOptions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,18 @@ import { Detail } from '../types'
2828

2929
// Simplifies the type check when dealing with ListItem and related components
3030
export const getDetailOptions = (detail: Detail) => {
31-
let accessory, padding, hoverDisclosure, content
31+
let accessory, padding, hoverDisclosure, content, width
3232

3333
if (typeof detail === 'object' && detail && 'options' in detail) {
3434
accessory = detail.options.accessory
3535
content = detail.content
3636
padding =
3737
detail.options.padding === undefined || detail.options.padding === true
3838
hoverDisclosure = detail.options.hoverDisclosure
39+
width = detail.options.width
3940
} else {
4041
content = detail
4142
}
4243

43-
return { accessory, content, hoverDisclosure, padding }
44+
return { accessory, content, hoverDisclosure, padding, width }
4445
}

packages/components/src/Tree/Tree.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ describe('Tree', () => {
196196
</Tree>
197197
)
198198

199-
expect(screen.queryByText('Tree Detail')).not.toBeVisible()
199+
expect(screen.queryByText('Tree Detail')).not.toBeInTheDocument()
200200
fireEvent.mouseEnter(screen.getByText('Tree Label'), { bubbles: true })
201-
expect(screen.queryByText('Tree Detail')).toBeVisible()
201+
expect(screen.queryByText('Tree Detail')).toBeInTheDocument()
202202
})
203203

204204
describe('color', () => {

packages/components/src/Tree/TreeItem.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ describe('TreeItem', () => {
7676
</TreeItem>
7777
)
7878

79-
expect(screen.queryByText('Detail')).not.toBeVisible()
79+
expect(screen.queryByText('Detail')).not.toBeInTheDocument()
8080
fireEvent.mouseEnter(screen.getByText('Label'), { bubbles: true })
81-
expect(screen.queryByText('Detail')).toBeVisible()
81+
expect(screen.queryByText('Detail')).toBeInTheDocument()
8282
})
8383

8484
test('Triggers onClickWhitespace when indent padding is clicked, itemRole = "none", and labelBackgroundOnly = true', () => {

packages/components/src/Tree/stories/FieldItem.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export const FieldItem: FC<FieldItemProps> = ({
105105
accessory: true,
106106
hoverDisclosure: !isFieldMenuOpen,
107107
padding: false,
108+
width: 48,
108109
},
109110
}}
110111
onKeyDown={(event) => {
@@ -130,7 +131,7 @@ export const FieldItem: FC<FieldItemProps> = ({
130131
>
131132
<Truncate>{children}</Truncate>
132133
</Flex>
133-
<HoverDisclosure visible={isPivot} strategy="display">
134+
<HoverDisclosure visible={isPivot}>
134135
<IconButton
135136
icon={<SubdirectoryArrowLeft />}
136137
onClick={() => setIsPivot(!isPivot)}
@@ -141,10 +142,7 @@ export const FieldItem: FC<FieldItemProps> = ({
141142
tooltipPlacement="top"
142143
/>
143144
</HoverDisclosure>
144-
<HoverDisclosure
145-
visible={isFilter}
146-
strategy={isPivot ? 'visibility' : 'display'}
147-
>
145+
<HoverDisclosure visible={isFilter} width={isPivot ? 24 : undefined}>
148146
<IconButton
149147
onClick={() => setIsFilter(!isFilter)}
150148
toggle={isFilter}

packages/components/src/utils/HoverDisclosure/HoverDisclosure.tsx

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,24 @@ import { HoverDisclosureContext } from './HoverDisclosureContext'
3030
export interface HoverDisclosureProps {
3131
visible?: boolean
3232
/**
33-
* Specify strategy to use for hiding content. Visibility is preferred
34-
* as it is generally more accessible but `display` will _not_ reserve
35-
* visible space when hidden and may be required when attempt to achieve
36-
* certain layouts.
37-
*
38-
* @default 'visibility'
33+
* In some circumstances it's required to reserve space for the hidden content
34+
* before it is revealed. Specifying this will reserve a space of the specified
35+
* width (in pixels)
3936
*/
40-
strategy?: 'visibility' | 'display'
37+
width?: number
4138
}
4239

4340
export const HoverDisclosure: FC<HoverDisclosureProps> = ({
4441
children,
45-
strategy = 'visibility',
42+
width,
4643
visible,
4744
}) => {
4845
const context = useContext(HoverDisclosureContext)
4946
const isVisible = visible || context.visible
5047

51-
const style: CSSProperties =
52-
strategy === 'visibility'
53-
? { visibility: isVisible ? 'visible' : 'hidden' }
54-
: { display: isVisible ? 'initial' : 'none' }
48+
const style: CSSProperties = width
49+
? { flexBasis: width, flexShrink: 0, width }
50+
: {}
5551

56-
return <div style={style}>{children}</div>
52+
return <div style={style}>{isVisible ? children : null}</div>
5753
}

0 commit comments

Comments
 (0)