-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix(OverflowMenu): check for custom closeMenu method #7456
fix(OverflowMenu): check for custom closeMenu method #7456
Conversation
❌ Deploy preview for carbon-components-react failed. 🔨 Explore the source changes: 15d7140 🔍 Inspect the deploy logs: https://app.netlify.com/sites/carbon-components-react/deploys/60076b24f555ba00077a4ad0 |
✔️ Deploy preview for carbon-elements ready! 🔨 Explore the source changes: 15d7140 🔍 Inspect the deploy logs: https://app.netlify.com/sites/carbon-elements/deploys/60076b24893dce0007061eab 😎 Browse the preview: https://deploy-preview-7456--carbon-elements.netlify.app |
@@ -494,7 +494,7 @@ class OverflowMenu extends Component { | |||
const childrenWithProps = React.Children.toArray(children).map( | |||
(child, index) => | |||
React.cloneElement(child, { | |||
closeMenu: this.closeMenu, | |||
closeMenu: child.props.closeMenu || this.closeMenu, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would we need to run both functions instead of deferring to a given child
closeMenu
? Seems like this.closeMenu
has some state logic that we want to run but I might be misunderstanding 👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the main intention is to allow a function that is different from or replaces the default closeMenu
(without expanding the component API). if the user still wants to run the existing logic they can use the existing onClose
prop. maybe it would be more preferable to just add a boolean prop that controls whether or not the menu will close on selection of an item?
Closes #6412
This PR prevents custom
closeMenu
methods from being overwritten by the default method in order to support a wider range of interactions on the overflow menuChangelog
Changed
closeMenu
before cloning the element and assigning a default value for the functionTesting / Reviewing
confirm that adding a custom
closeMenu
method on anOverflowMenuItem
will not be overwritten