Is there a better alternative to cloneElement?
See original GitHub issueWhen using ToggleButton from lab package and wrapping it in tooltip it raises a warning:
Warning: Failed prop type: The following properties are not supported: selected, onChange. Please remove them.
- This is not a v1.x issue.
- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior
It should be possible to add a tooltip to ToggleButton
Current Behavior
<Tooltip title="left" placement="top">
<ToggleButton value="left">
<FormatAlignLeftIcon />
</ToggleButton>
</Tooltip>
Steps to Reproduce
Link: https://codesandbox.io/s/q7m82k4024
- Wrap the ToggleButton inside a Tooltip
- Run the code
- See the console for warning
Context
Since ToggleButtons are IconButton (at least that’s how we intend to use it) it would be helpful to a user to see what that button will do and the best way for that is Tooltip
Your Environment
Tech | Version |
---|---|
Material-UI | v3.1.0 |
React | v16.4 |
Browser | any |
Issue Analytics
- State:
- Created 5 years ago
- Reactions:13
- Comments:23 (12 by maintainers)
Top Results From Across the Web
Is there a better alternative to cloneElement? #12921 - GitHub
This component assumes it's immediate children will be buttons and passes 'selected' and 'onChange' props. Now, this can be solved if Tooltip ......
Read more >When should I be using React.cloneElement vs this.props ...
Look at Vennesa's answer instead, which is a better explanation. Original: First of all, the React.cloneElement example only works if your child ...
Read more >react: spreading children vs cloneelement - code-comments
Instead of lifting the state, there's an alternative approach - but it means no longer simply spreading the children props as in the...
Read more >Advanced composition in React: cloneElement, HOCs and ...
It's similar to using cloneElement , but you give the component passing the ... This solution is more flexible than the previous ones....
Read more >cloneElement - React Docs
Using cloneElement is uncommon and can lead to fragile code. See common alternatives. cloneElement lets you create a new React element using another...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Guys,
Tooltip
breaksToggleButton
.The selected CSS class will not get set if you wraps the
Tooltip
around the button.Without
Tooltip
you can see that the proper class is being added:When wrapping the
ToggleButton
with a tooltip, it breaks:Just a random thought but wouldn’t it be better to create a context in ToggleButtonGroup that the ToggleButtons can listen to? That way we could get away from the cloneElement pattern.