-
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)
#2602
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 20a5089 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 |
@@ -56,7 +54,7 @@ export const SplitButton = InferredPolymorphic<SplitButtonProps, 'button'>( | |||
ref: React.Ref<any>, | |||
) => { | |||
const { Component } = useInferredPolymorphic(as, rest, 'button'); | |||
const { darkMode, theme } = useDarkMode(darkModeProp); | |||
const { theme } = useDarkMode(darkMode); |
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.
We still want to use the darkMode
value returned from useDarkMode
because it reads and returns the darkMode
value from the parent LeafyGreenProvider. If darkMode
is passed into the component, it will take precedence over the LeafyGreenProvider
darkMode
value.
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.
If
darkMode
is passed into the component, it will take precedence over theLeafyGreenProvider
darkMode
value.
That's the exact the behaviour I'd expect though?
I expect the Button
and Menu
(rendered internally in SplitButton
) to call useDarkMode
by themselves to apply the right theme from the provider iff a darkMode
prop isn't passed to the SplitButton
.
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.
Thank you for pointing this out! You're absolutely correct.
However, we’ll stick with the current implementation, as we intentionally pass darkMode
directly to the LeafyGreenProvider
. This approach is deliberate and aligns with how we typically handle darkMode
across other LeafyGreen components.
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 do see this pattern being used a lot of places and being documented here: https://github.com/mongodb/leafygreen-ui/blob/main/STYLEGUIDE.md#passing-darkmode-to-children
I'll go ahead and revert that change 👍
I do however think this decision should be revisited, wrapping components in multiple layers of these context providers isn't "free" and they all contribute to a messier component graph as well as potential rendering bottlenecks - especially when the context updates.
I've drafted this again, since there are more changes that I'd like to include: It isn't possible to pass menu separators through the |
@@ -53,18 +53,22 @@ type ButtonProps = Omit< | |||
'rightGlyph' | 'href' | 'as' | 'variant' | |||
>; | |||
|
|||
export type SelectedMenuProps = Omit< | |||
export type SelectedMenuProps = Pick< |
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 think this makes sense, this way we are explicit with what props menu accepts
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.
Thanks for the PR! The type updates make sense. However, we wouldn't want to remove the LeafyGreenProvider
since passing darkMode
to the LeafyGreenProvider
is an explicit pattern we've adopted in other LG components.
4bc2c80
to
20a5089
Compare
I've created one more PR with suggestioned breaking changes to the |
✍️ Proposed changes
As per my suggestion in #2601, future regressions could be avoided if the types derived from
MenuProps
intended for pass-through is allow-listed via aPick
instead of deny-listed viaOmit
.This change is breaking, since it's removing a lot of props from the
SplitButton
which were never actually passed through to theMenu
.This also optimize the internals by passingdarkMode
directly to child components instead of wrapping them in a newLeafyGreenProvider
- this is not breaking, just a "drive-by" optimization.NOTE: If #2601 merge before this PR, it needs to be updated to add
renderDarkMenu
in the allow-list.✅ Checklist
For bug fixes, new features & breaking changes
yarn changeset
and documented my changesFor new components
🧪 How to test changes
@leafygreen-ui/split-button
to a projectonEnter
orrenderDarkMenu
props are available on theSplitButton
.onEnter
orrenderDarkMenu
props are no longer available on theSplitButton
.