Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ActionMenu having null children #1445

Merged
merged 3 commits into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion react/ActionMenu/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const hideMenu = () => setState({ menuDisplayed: false });
{state.menuDisplayed &&
<ActionMenu
onClose={hideMenu}>
<ActionMenuItem left={<Icon icon='file' />}>Item 1</ActionMenuItem>
<ActionMenuItem left={<Icon icon='file' />} right={<Icon icon='warning' />}>Item 1</ActionMenuItem>
<ActionMenuItem left={<Icon icon='right' />}>Item 2</ActionMenuItem>
<ActionMenuItem left={<Icon icon='file' />}>
<div>
Expand Down
11 changes: 11 additions & 0 deletions react/ActionMenu/__snapshots__/index.spec.jsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ActionMenu should support null children 1`] = `
<div
className="styles__c-actionmenu___22Fp1 styles__c-actionmenu--inline___1SXZa"
>
<ActionMenuItem>
Item 1
</ActionMenuItem>
</div>
`;
2 changes: 1 addition & 1 deletion react/ActionMenu/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const ActionMenu = ({
})}
>
{React.Children.map(children, child =>
child.type === ActionMenuHeader && isDesktop ? null : child
child && child.type === ActionMenuHeader && isDesktop ? null : child
)}
</div>
</ActionMenuWrapper>
Expand Down
24 changes: 24 additions & 0 deletions react/ActionMenu/index.spec.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react'
import { mount } from 'enzyme'

import ActionMenu, { ActionMenuItem } from './'
import { fixPopperTesting } from '../Popper/testing'

describe('ActionMenu', () => {
fixPopperTesting()

it('should support null children', () => {
const comp = mount(
<ActionMenu onClose={jest.fn()}>
<ActionMenuItem>Item 1</ActionMenuItem>
{null}
</ActionMenu>
)
expect(
comp
.find(ActionMenuItem)
.parent()
.getElement()
).toMatchSnapshot()
})
})
21 changes: 21 additions & 0 deletions react/Popper/testing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Fixes the error "TypeError: document.createRange is not a function" in jest,
// see https://github.com/mui-org/material-ui/issues/15726#issuecomment-493124813
export const fixPopperTesting = () => {
let createRangeBackup

beforeAll(() => {
createRangeBackup = global.document.createRange
global.document.createRange = jest.fn(() => ({
setStart: () => {},
setEnd: () => {},
commonAncestorContainer: {
nodeName: 'BODY',
ownerDocument: document
}
}))
})

afterAll(() => {
global.document.createRange = createRangeBackup
})
}
3 changes: 3 additions & 0 deletions react/__snapshots__/examples.spec.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ exports[`ActionMenu should render examples: ActionMenu 1`] = `
<use xlink:href=\\"#file\\"></use>
</svg></div>
<div class=\\"styles__bd___1Uv-F u-mr-1\\">Item 1</div>
<div class=\\"styles__img___3SHpG u-mr-1\\"><svg class=\\"styles__icon___23x3R\\" width=\\"16\\" height=\\"16\\">
<use xlink:href=\\"#warning\\"></use>
</svg></div>
</div>
<div class=\\"styles__media___cSJMp styles__media--top___K9w0I styles__c-actionmenu-item___gODqd\\">
<div class=\\"styles__img___3SHpG u-mh-1\\"><svg class=\\"styles__icon___23x3R\\" width=\\"16\\" height=\\"16\\">
Expand Down