question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Tooltip] Add disabled prop

See original GitHub issue
  • I have searched the issues of this repository and believe that this is not a duplicate.

I found this issue which is vaguely related, I think: #1500

Summary 💡

Sometimes it’s useful to have an uncontrolled tooltip for, say, an icon button that opens a menu. When the menu is open, the tooltip might overlap with the menu, so it’s best to hide it.

Now, you can hide the tooltip by setting the title to an empty string, but this has the issue that the tooltip suddenly collapses while fading away, which is not very nice. I’ve tried other ways like disabling the listeners but that causes a lot of problems.

Making the tooltip controlled and manually implementing the event listeners and all is overkill for just this thing.

I think it could be easily solved with a disabled property, so that it can be safely disabled without this ugly UI issue while remaining uncontrolled.

Examples 🌈

Instead of:

<Tooltip title={menuOpen ? '' : tooltip} />

Do:

<Tooltip disabled={menuOpen} />

Motivation 🔦

I can share the app I’m building with you if you need more details of a real use-case. Just ask.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
DaniGuardiolacommented, May 28, 2020

Okay, well in case anybody has this same issue, here’s a workaround:

import React, { useState, useEffect } from 'react'

import { Tooltip } from '@material-ui/core'

function DisableableTooltip ({
  disabled,
  children,
  ...tooltipProps
}: TooltipProps & { disabled: boolean }) {
  const [open, setOpen] = useState(false)

  useEffect(() => {
    if (disabled) setOpen(false)
  }, [disabled])

  return (
    <Tooltip
      {...tooltipProps}
      open={open}
      onOpen={() => !disabled && setOpen(true)}
      onClose={() => setOpen(false)}
    >
      {children}
    </Tooltip>
  )
}

Use this component as a drop-in replacement of Toolbar with the additional disabled property.

1reaction
eps1loncommented, May 28, 2020

I meant that I do understand what you’re seeing but not how we can reproduce this with Material-UI.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to enable Bootstrap tooltip on disabled button?
You can get disabled buttons to display tooltip by overriding the "pointer-events" property set by bootstrap.
Read more >
How to Show tooltip on disabled elements and ... - Syncfusion
Add a disabled element like the button element into a div whose display style is set to inline-block . · Set the pointer...
Read more >
How to enable Bootstrap tooltip on disabled button
To trigger tooltip on disabled button by wrapping them in <span> span tag and <div> div tag and then adding 'data-toggle','data-placement' ...
Read more >
[Tooltip] Add disabled prop #21204 - mui/material-ui - GitHub
Now, you can hide the tooltip by setting the title to an empty string, but this has the issue that the tooltip suddenly...
Read more >
Displaying a Tooltip on Disabled Elements - Kendo UI for ...
To show a tooltip on a disabled element, set the pointer-events CSS property to auto . For example, to display a Tooltip on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found