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

Support ActionMenu having null children #1445

merged 3 commits into from Apr 28, 2020

Conversation

y-lohse
Copy link
Contributor

@y-lohse y-lohse commented Apr 23, 2020

In Drive we have an ActionMenu but not all items are visible at all time — if one of the items should be hidden, it returns null instead, as is common in React. This was breaking ActionMenu because it was checking null.type.

I also added an example for the right prop of ActionMenuItem so that we have visual regression tests for it.

@y-lohse y-lohse requested a review from ptbrowne as a code owner April 23, 2020 09:15
@y-lohse y-lohse requested a review from Crash-- April 23, 2020 09:16
@ptbrowne
Copy link
Contributor

ptbrowne commented Apr 23, 2020

Looking good, but can you add a test for the null case ?

@Crash--
Copy link
Contributor

Crash-- commented Apr 23, 2020

In Drive we have an ActionMenu but not all items are visible at all time — if one of the items should be hidden, it returns null instead, as is common in React

We're thinking about that and it's not impossible that instead of hiding features, we'll simply "disabled them" by displaying them with a special style and removing the onclick action.

@y-lohse
Copy link
Contributor Author

y-lohse commented Apr 24, 2020

We're thinking about that and it's not impossible that instead of hiding features, we'll simply "disabled them" by displaying them with a special style and removing the onclick action.

Some will likely stay fully hidden, for example those that we want either in the topbar or in the menu depending on the context.

Looking good, but can you add a test for the null case ?

Yup, done !

const comp = mount(
<ActionMenu onClose={jest.fn()}>
<ActionMenuItem>Item 1</ActionMenuItem>
null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a null string here ?

I think you want { null }.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️thanks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the testing passing with the "null" string ? If yes, this could be a problem.

nodeName: 'BODY',
ownerDocument: document
}
}))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have issue for testing component using Tooltip from MUI. See mui/material-ui#15726 (comment)

jsdom-16 fix the issue, but we need to use https://www.npmjs.com/package/jest-environment-jsdom-sixteen. I tried few months ago but still the issue. Maybe it's fine now.

Copy link
Contributor

@ptbrowne ptbrowne Apr 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AMHA this should not be in this test file and should be called with a name that reviewers can understand.

Tooltip/testing.js or testing.js, something like that:

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

  afterAll(() => {
    global.document.createRange = createRangeBackup
  })
}

This way we do not need a comment, it's clearer for the reviewer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and we can import it from other libs 👍

react/Popper/testing.js Outdated Show resolved Hide resolved
@ptbrowne
Copy link
Contributor

👍

@y-lohse y-lohse merged commit 63e20d2 into master Apr 28, 2020
@delete-merged-branch delete-merged-branch bot deleted the am-null-child branch April 28, 2020 08:12
cozy-bot pushed a commit that referenced this pull request Apr 28, 2020
@cozy-bot
Copy link

🎉 This PR is included in version 35.11.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants