Skip to content

Commit ea6e028

Browse files
Luke BowermanElliot Park
andauthored
fix(MenuList): Deal with MenuDividers in unexpected places (#2079)
* fix(MenuList): Deal with MenuDividers in unexpected places * Fxix color usage * MenuDivider should properly absorb props * Snapshots * Fix for default-margin in Safari Co-authored-by: Elliot Park <[email protected]>
1 parent ca71721 commit ea6e028

File tree

6 files changed

+66
-13
lines changed

6 files changed

+66
-13
lines changed
61 Bytes
Loading
5.77 KB
Loading

packages/components/src/List/ListItemWrapper.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export const ListItemWrapper = styled(ListItemWrapperInternal)`
8989
flex: 1;
9090
font-size: inherit;
9191
font-weight: inherit;
92+
margin: 0; /* safari has default margin */
9293
min-width: 0;
9394
outline: none;
9495
text-align: left;

packages/components/src/Menu/MenuDivider.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@
2424
2525
*/
2626

27+
import React, { FC } from 'react'
2728
import styled from 'styled-components'
2829
import { SpaceProps, space } from '@looker/design-tokens'
30+
import { Divider } from '../Divider'
2931

30-
export const MenuDivider = styled.li<SpaceProps>`
32+
const MenuDividerLayout: FC<{}> = (props) => (
33+
<li {...props} aria-hidden="true">
34+
<Divider />
35+
</li>
36+
)
37+
38+
export const MenuDivider = styled(MenuDividerLayout)<SpaceProps>`
3139
${space}
32-
border: none;
33-
border-top: 1px solid ${({ theme: { colors } }) => colors.ui2};
34-
35-
& + &,
36-
&:first-child,
37-
&:last-child {
38-
display: none;
39-
}
4040
`

packages/components/src/Menu/MenuList.story.tsx

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import React, { FC, Fragment } from 'react'
2828
import { Story } from '@storybook/react/types-6-0'
2929
import { IconNames } from '@looker/icons'
30-
import { Box, Grid } from '../Layout'
30+
import { Box, Grid, Space } from '../Layout'
3131
import { DensityRamp } from '../List/types'
3232
import { MenuHeading, MenuList, MenuItem, MenuItemProps, MenuDivider } from '.'
3333

@@ -139,6 +139,46 @@ export const MenuHeadingOverride = () => (
139139
</MenuList>
140140
)
141141

142+
/**
143+
* This storyshot is specifically for checking that space above the first item
144+
* and space below the last item is maintained even with extraneous dividers.
145+
*/
146+
export const MenuListSpacing = () => (
147+
<Space p="medium" style={{ background: '#ff8c69' }}>
148+
<Box bg="background">
149+
<MenuList>
150+
<MenuDivider />
151+
<MenuItem selected>Top Item</MenuItem>
152+
<MenuItem selected>Top Item</MenuItem>
153+
<MenuDivider />
154+
<MenuItem selected>Bottom Item</MenuItem>
155+
<MenuItem selected>Bottom Item</MenuItem>
156+
<MenuDivider />
157+
</MenuList>
158+
</Box>
159+
<Box bg="background">
160+
<MenuList>
161+
<MenuItem selected>Top Item</MenuItem>
162+
<MenuItem selected>Top Item</MenuItem>
163+
<MenuDivider />
164+
<MenuItem selected>Bottom Item</MenuItem>
165+
<MenuItem selected>Bottom Item</MenuItem>
166+
<MenuDivider />
167+
</MenuList>
168+
</Box>
169+
<Box bg="background">
170+
<MenuList>
171+
<MenuDivider />
172+
<MenuItem selected>Top Item</MenuItem>
173+
<MenuItem selected>Top Item</MenuItem>
174+
<MenuDivider />
175+
<MenuItem selected>Bottom Item</MenuItem>
176+
<MenuItem selected>Bottom Item</MenuItem>
177+
</MenuList>
178+
</Box>
179+
</Space>
180+
)
181+
142182
export default {
143183
component: MenuList,
144184
title: 'MenuList',

packages/components/src/Menu/MenuList.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { width, WidthProps } from '@looker/design-tokens'
2828
import React, { forwardRef, Ref } from 'react'
2929
import styled from 'styled-components'
3030
import { List, ListProps } from '../List'
31+
import { Divider } from '../Divider'
3132
import { MenuDivider } from './MenuDivider'
3233
import { MenuItem } from './MenuItem'
3334
import { NestedMenuProvider } from './NestedMenuProvider'
@@ -55,13 +56,24 @@ export const MenuList = styled(MenuListInternal)`
5556
min-width: 12rem;
5657
overflow: auto;
5758
58-
${MenuDivider},
59+
> :first-child {
60+
margin-top: ${({ theme }) => theme.space.xsmall};
61+
62+
${Divider} {
63+
display: none;
64+
}
65+
}
66+
5967
${MenuDivider} + ${MenuItem},
60-
> *:first-child {
68+
${MenuItem} + ${MenuDivider} {
6169
margin-top: ${({ theme }) => theme.space.xsmall};
6270
}
6371
64-
> *:last-child {
72+
> :last-child {
6573
margin-bottom: ${({ theme }) => theme.space.xsmall};
74+
75+
${Divider} {
76+
display: none;
77+
}
6678
}
6779
`

0 commit comments

Comments
 (0)