Skip to content

Commit c57da18

Browse files
authored
MenuItem supports Artwork (#1242)
* MenuItem supports Artwork * updated after revew - remove snapshots of tests * ready for final review
1 parent 23bb108 commit c57da18

File tree

6 files changed

+89
-681
lines changed

6 files changed

+89
-681
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
### Changed
1717

18+
- update MenuItem to support Artwork
1819
- `MenuDisclosure` - tooltip placement now defaults to `bottom`
1920
- `Select` and `SelectMulti` with `isFilterable` or `freeInput` no longer cancel the first click outside when the list is open
2021
- update `Tab` to scroll left to right when overflow

packages/components/src/Menu/MenuItem.test.tsx

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,39 @@
2626

2727
import 'jest-styled-components'
2828
import React from 'react'
29-
import { assertSnapshot } from '@looker/components-test-utils'
29+
import { renderWithTheme } from '@looker/components-test-utils'
30+
import { screen } from '@testing-library/react'
3031

3132
import { MenuItem } from './MenuItem'
3233

33-
test('MenuItem', () => {
34-
assertSnapshot(<MenuItem>who!</MenuItem>)
35-
})
36-
test('MenuItem - icon', () => {
37-
assertSnapshot(<MenuItem icon="Beaker">who!</MenuItem>)
38-
})
39-
test('MenuItem - detail', () => {
40-
assertSnapshot(<MenuItem detail="Is an excellent question">who!</MenuItem>)
41-
})
34+
describe('MenuItem', () => {
35+
test('MenuItem renders', () => {
36+
renderWithTheme(<MenuItem>who!</MenuItem>)
37+
expect(screen.getByText('who!')).toBeVisible()
38+
})
39+
40+
test('MenuItem - detail', () => {
41+
renderWithTheme(<MenuItem detail="Is an excellent question">who!</MenuItem>)
42+
expect(screen.getByText('Is an excellent question')).toBeVisible()
43+
})
44+
45+
test('MenuItem - icon', () => {
46+
renderWithTheme(<MenuItem icon="Beaker">Icon</MenuItem>)
47+
expect(screen.getByText('Icon')).toBeVisible()
48+
})
4249

43-
test('MenuItem - current', () => {
44-
assertSnapshot(
45-
<MenuItem current icon="Home">
46-
who!
47-
</MenuItem>
48-
)
50+
test('MenuItem - artwork', () => {
51+
renderWithTheme(
52+
<MenuItem
53+
iconArtwork={
54+
<svg xmlns="http://www.w3.org/2000/svg">
55+
<title>SVG Title Here</title>
56+
</svg>
57+
}
58+
>
59+
Artwork
60+
</MenuItem>
61+
)
62+
expect(screen.getByTitle('SVG Title Here')).toBeInTheDocument()
63+
})
4964
})

packages/components/src/Menu/MenuItem.tsx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ import { MenuContext, MenuItemContext } from './MenuContext'
3434
import { MenuItemLayout, MenuItemLayoutGrid } from './MenuItemLayout'
3535

3636
export interface MenuItemProps extends CompatibleHTMLProps<HTMLElement> {
37+
iconArtwork?: ReactNode
3738
compact?: boolean
38-
39-
detail?: ReactNode
40-
icon?: IconNames
4139
/**
4240
* Indicates the MenuItem is checked
4341
*/
@@ -49,6 +47,8 @@ export interface MenuItemProps extends CompatibleHTMLProps<HTMLElement> {
4947
* @default 'button'
5048
*
5149
*/
50+
detail?: ReactNode
51+
icon?: IconNames
5252
itemRole?: 'link' | 'button'
5353
}
5454

@@ -62,6 +62,7 @@ const MenuItemInternal: FC<MenuItemProps> = (props) => {
6262
disabled,
6363
href,
6464
icon,
65+
iconArtwork,
6566
itemRole,
6667
onBlur,
6768
onClick,
@@ -103,18 +104,20 @@ const MenuItemInternal: FC<MenuItemProps> = (props) => {
103104

104105
const renderedIconID = useID(props.id)
105106

106-
const renderedIcon = icon ? (
107-
<Icon
108-
name={icon}
109-
mr="xsmall"
110-
size={24 / (compact ? 1.25 : 1)}
111-
color="text1"
112-
/>
113-
) : (
114-
renderIconPlaceholder && (
115-
<div data-testid={`menu-item-${renderedIconID}-icon-placeholder`} />
107+
const renderedIcon =
108+
icon || iconArtwork ? (
109+
<Icon
110+
artwork={iconArtwork}
111+
color="text1"
112+
name={icon}
113+
size={24 / (compact ? 1.25 : 1)}
114+
mr="xsmall"
115+
/>
116+
) : (
117+
renderIconPlaceholder && (
118+
<div data-testid={`menu-item-${renderedIconID}-icon-placeholder`} />
119+
)
116120
)
117-
)
118121

119122
const Component = itemRole === 'link' ? 'a' : 'button'
120123

0 commit comments

Comments
 (0)