-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[ButtonGroup] Support different elements under ButtonGroup #28645
Merged
ZeeshanTamboli
merged 25 commits into
mui:master
from
ZeeshanTamboli:issue/17226-support-different-elements-to-ButtonGroup
Nov 2, 2021
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
38c2624
replace React.cloneElement with Context API in ButtonGroup for suppor…
ZeeshanTamboli abdc7e6
use ButtonGroupContext in Button component
ZeeshanTamboli 7bf3f2b
test: ButtonGroup context
ZeeshanTamboli b2a5904
test: ButtonGroup context
ZeeshanTamboli b035d15
yarn prettier
ZeeshanTamboli aa88456
add types for ButtonGroupContext
ZeeshanTamboli 14a6172
Merge branch 'master' into issue/17226-support-different-elements-to-…
ZeeshanTamboli 3cbe153
yarn prettier
ZeeshanTamboli 9f6dddb
yarn workspace framer build
ZeeshanTamboli 3475901
Merge branch 'master' into issue/17226-support-different-elements-to-…
ZeeshanTamboli 069e626
Merge branch 'master' into issue/17226-support-different-elements-to-…
ZeeshanTamboli e07da28
code review changes
ZeeshanTamboli b66656c
yarn prettier
ZeeshanTamboli 3cd743d
test: pass props to ButtonGroup to test if it is received to Context …
ZeeshanTamboli 5fa41eb
Merge branch 'master' into issue/17226-support-different-elements-to-…
ZeeshanTamboli 3770a76
fix cylic import
ZeeshanTamboli d198923
fix cyclic import
ZeeshanTamboli 5989f53
Merge branch 'master' into issue/17226-support-different-elements-to-…
ZeeshanTamboli e1e6657
use import type to avoid circular dependency
ZeeshanTamboli e255ea2
change destructuring default values syntax to support JSDoc @default …
ZeeshanTamboli 8c4ca0d
fix(Button): disableRipple default value
ZeeshanTamboli f5f4c2a
fix(Button): initialize button props which may have context values or…
ZeeshanTamboli 2773bf9
Merge branch 'master' into issue/17226-support-different-elements-to-…
ZeeshanTamboli 6b739f4
add TODO comment
ZeeshanTamboli 1c026b8
yarn prettier
ZeeshanTamboli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/mui-material/src/ButtonGroup/ButtonGroupContext.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as React from 'react'; | ||
import type { ButtonGroupProps } from './ButtonGroup'; | ||
|
||
interface IButtonGroupContext { | ||
className?: string; | ||
color?: ButtonGroupProps['color']; | ||
disabled?: boolean; | ||
disabledElevation?: boolean; | ||
disableFocusRipple?: boolean; | ||
disableRipple?: boolean; | ||
fullWidth?: boolean; | ||
size?: ButtonGroupProps['size']; | ||
variant?: ButtonGroupProps['variant']; | ||
} | ||
|
||
/** | ||
* @ignore - internal component. | ||
*/ | ||
const ButtonGroupContext = React.createContext<IButtonGroupContext>({}); | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
ButtonGroupContext.displayName = 'ButtonGroupContext'; | ||
} | ||
|
||
export default ButtonGroupContext; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Using
||
looks wrong here. IfdisableElevationContext
is true anddisableElevationProp
false,disableElevation
should be false, not true.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.
Otherwise, we could explore the creation of a helper. I assume that it's always the same case when a parent component uses the context to change default values on its 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.
Nice catch. That is interesting! Need to think how to handle these button boolean props if used with context.
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 assume this would work:
I saw it used by Michal
const ButtonRoot: React.ElementType = component ?? components.Root ?? 'button';
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.
@oliviertassinari I'm afraid that his is not supposed to be used here. If i recall it correctly,
??
checks nullity (undefined/null) instead of falsy/truthy.Example here (i just wrote it)
So if a user has
disableElevationProp={false} disableElevationContext={true}
, this version with??
will return afalse
instead oftrue
. (see theexception_case
in that example)component ?? components.Root ?? 'button'
was correctly used or equallycomponents?.Root ?? 'button'
.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.
It's interesting no one has filed a bug with this yet. I'd say let's keep the current behavior and fix it for the next major (and in unstyled Button when ButtonGroup is introduced there).
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.
Okay. With that I think there is nothing else pending in this PR. Resolving this conversation.
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.
@ZeeshanTamboli could we add a todo to change this behavior in v6?
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.
Added.
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.
@ZeeshanTamboli it looks like more bugs.