-
Notifications
You must be signed in to change notification settings - Fork 66
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
Refactored SplitButton (breaking - more) #2604
base: main
Are you sure you want to change the base?
Refactored SplitButton (breaking - more) #2604
Conversation
🦋 Changeset detectedLatest commit: c0ff482 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Delete unused types
@@ -26,14 +26,14 @@ import { Align, Justify, SplitButtonProps, Variant } from './SplitButton.types'; | |||
export const SplitButton = InferredPolymorphic<SplitButtonProps, 'button'>( | |||
( | |||
{ | |||
children, |
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.
I believe we decided on the menuItems
API to avoid confusion on whether the children should be the menu items or the button label
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.
avoid confusion on whether the children should be the menu items or the button label
That is easily disambiguated through a comment on the prop? Right now the component takes children
and just throws them away? I feel that's more confusing 🤷 and much less expressive.
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.
I've updated the description above with more context on the issues I see with of the current menuItems
prop.
I'm working on a feature in Compass where I'd like to pass arbitrary elements to be rendered in the
SplitButton
menu.I want to render a menu containing:
MenuSeparator
elements.MenuItem
elements with controls that shouldn't cause the menu to close when clicked.MenuItem
elements to help me abstract aprop
which needs to be passed to multiple props on theMenuItem
.The current implementation gets items through an
menuItems
prop (an array ofReact.ReactElement
elements) - which has multiple drawbacks:MenuItem
is skipped when rendered, meaning it can't render separators, sub-menus or any components wrappingMenuItem
- making it much less expressive with no apparent benefit.key
prop provided.✍️ Proposed changes
SplitButton
currently declare takingchildren
(from theButtonProps
) but these are never used internally. I suggest that these are instead passed into theMenu
. This will make themenuItems
prop obsolete.MenuItem
configurable, I suggest adding anonItemClick
prop taking a callback which will be called (just likeonChange
is called now) but also passed a second options object with a reference to the Reactelement
being clicked (to allow inspection of props) as well as aclose
function, which can be called to close the menu.onItemClick
used when no function is explicitly passed. Since the signature and semantics of this newonItemClick
prop is so similar toonChange
, I suggest removing the latter. The main caveat with this is that someone renaming theironChange
callback toonItemClick
now also has to explicitly call theclose
function in the callback.Before
After
NOTE: This builds upon #2602 and needs to be rebased once that gets merged. Once rebased, I'll update the changeset description, including examples of how to migrate to the two new props (
menuItems
→children
andonChange
→onItemClick
).✅ Checklist
For bug fixes, new features & breaking changes
yarn changeset
and documented my changesFor new components
🧪 How to test changes