-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Tooltip wrapped toggle buttons break highlight #18091
Comments
We have covered this problem a couple of times already. They are 3 possible approaches, 2 you can leverage today.
<ToggleButtonGroup
value={mode}
exclusive
onChange={(e, newValue) => setMode(newValue)}
>
<ToggleButton value="kill">
<Tooltip title="Set mode to kill">
<span>Kill</span>
</Tooltip>
</ToggleButton>
|
Could you give me a link with some code doing this? I would like to adapt this into our codebase. |
I got it working with props forwarding import React, { forwardRef, VFC } from 'react';
import ToggleButton, { ToggleButtonProps } from '@mui/material/ToggleButton';
import Tooltip, { TooltipProps } from '@mui/material/Tooltip';
type TooltipToggleButtonProps = ToggleButtonProps & {
TooltipProps: Omit<TooltipProps, 'children'>;
};
// Catch props and forward to ToggleButton
const TooltipToggleButton: VFC<TooltipToggleButtonProps> = forwardRef(
({ TooltipProps, ...props }, ref) => {
return (
<Tooltip {...TooltipProps}>
<ToggleButton ref={ref} {...props} />
</Tooltip>
);
}
);
export default TooltipToggleButton; |
We are doing this method on our ToggleButton however in adding the wrapping Tooltip it's breaking the ToggleButton styles, they are no longer grouped and instead look like two separate buttons. Do you have a workaround for this or do we need to specifically overwrite the styles to make it appear correct? Without TooltipWith Tooltip |
I'm starting to think this should be supported by |
Agreed with @modbender. That would be more useful than having to manually juggle the props forwarding! |
That must be a |
So far I've had success by applying the tooltip inside the <ToggleButton value={value}>
<span>Option 1</span>
<Tooltip title="Option 1 description">
<span
style={{
bottom: 0,
left: 0,
position: "absolute",
right: 0,
top: 0,
}}
></span>
</Tooltip>
</ToggleButton> |
For, ToggleButtons wrapped in a tooltip, the toggle highlight doesn't work.
I believe this may be similar to #13206
Current Behavior 😯
Tooltips break toggle buttons highlighting behavior.
Expected Behavior 🤔
I expect Tooltips to not affect highlighting behavior.
Steps to Reproduce 🕹
https://codesandbox.io/s/lingering-bird-6zrc4?fontsize=14
Context 🔦
I wanted to put a tooltip on the buttons so users know what the buttons do.
Your Environment 🌎
The text was updated successfully, but these errors were encountered: