-
-
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
[tooltip] Controlled state does not work #43965
Comments
@alyssaButlerIntegrityNext, I think there isn’t a need for the Button in the demo. The intention of the demo is to show how to control the open prop, which it’s already doing. Maybe we can remove the Button from the demo as it’s a bit confusing. |
Fair point, however the behavior is still not as I would expect as the hover interaction stays even with a controlled component. I have a video here of the sandbox from the demo, even if I set the prop open, when I hover the Tooltip no longer is controlled. My expectation is that the tooltip should only change on button click, is that incorrect? Screen.Recording.2024-10-02.at.16.09.22.mov |
import * as React from 'react';
import Button from '@mui/material/Button';
import Tooltip from '@mui/material/Tooltip';
export default function ControlledTooltips() {
const [open, setOpen] = React.useState(false);
const handleClick = () => {
setOpen(val=>!val);
};
return (
<Tooltip open={open} title="Add">
<Button onClick={handleClick} >Controlled</Button>
</Tooltip>
);
} @alyssaButlerIntegrityNext If you want Button onClick to control Tooltip, you can try above code. Note to maintainers: I still think we should remove Button from demo, as it's bit unusual to open Tooltip on Button click |
👋 Thanks for using this project! We use GitHub issues exclusively as a bug and feature requests tracker, however, this issue appears to be a support request. For support with Material UI please check out https://mui.com/material-ui/getting-started/support/. Thanks! If you have a question on Stack Overflow, you are welcome to link to it here, it might help others. |
Overall, It looks like we are asking support questions, so we are in the wrong place.
Tooltips are meant to be used with buttons, so I don't see how we could use anything else. |
Steps to reproduce
Link to live example: (Mui Website, Controlled Tooltips Section)
Steps:
Current behavior
The tooltip appears on hover, the button click appears to have no effect on the tooltip.
Expected behavior
The tooltip is not controlled by hover interactions but by button click. When I click on the button once, the tooltip should stay open even when I move my mouse away from the button. When I click the button again, the tooltip should disappear.
Context
No response
Your environment
npx @mui/envinfo
Search keywords: tooltip
The text was updated successfully, but these errors were encountered: