tooltip icon indicating copy to clipboard operation
tooltip copied to clipboard

mouseleave don't trigger on disabled inputs and button

Open afc163 opened this issue 10 years ago • 27 comments

<Tooltip title="mouseleave is not work">
  <button disabled>button text</button>
</Tooltip>

https://github.com/react-bootstrap/react-bootstrap/pull/1254

afc163 avatar Sep 11 '15 14:09 afc163

use this instead

<Tooltip title="mouseleave is not work">
  <span><button disabled>button text</button></span>
</Tooltip>

yiminghe avatar Sep 14 '15 13:09 yiminghe

对了这个地方 貌似 每次POP 起来 点DOCUMENT 空白消失的情况第一次都没问题,第二次 都提示 this.popupInstance.getPopupDomNode is not a function 第一次都是可以的,我这里用的REACT 1.4 RC 设置Tooltip.props.trigger ="click"

tianyingchun avatar Oct 03 '15 13:10 tianyingchun

突然发现是之前提的 chrome bug... https://code.google.com/p/chromium/issues/detail?id=120132

https://code.google.com/p/chromium/issues/detail?id=536905

yiminghe avatar Oct 12 '15 02:10 yiminghe

+1, any work arounds?

swarajban avatar Jan 13 '16 06:01 swarajban

好像和这个相关 https://github.com/facebook/react/pull/5762

benjycui avatar Jan 13 '16 09:01 benjycui

同样碰到这个问题。暂时用这样的方式解决了:

<span style={{display: 'inline-block', padding: 1, marginTop: -1}}>
    <button disabled>提交</button>
</span>

不知道有没有更好的办法

anjianshi avatar May 30 '16 07:05 anjianshi

貌似现在加 span 的方式也不好使了:http://codepen.io/anon/pen/xRWRRY?editors=001

afc163 avatar Dec 05 '16 14:12 afc163

@afc163 是的 我试了加span也无效

bairedzhang avatar Jan 15 '17 00:01 bairedzhang

https://github.com/react-bootstrap/react-bootstrap/issues/1588#issuecomment-174238956

afc163 avatar Feb 13 '17 03:02 afc163

加了 span 更不好使了, bug 如下:

  1. 在ButtonGroup 下, 样式错误, 分割线变粗,为 2px image
  2. 设置在 button 上的额外样式失效了, btn-intelligent, 本来设置在 button 上的 image

sandwich99 avatar Jun 13 '17 03:06 sandwich99

Any progress on fixing this?

image

ajbeaven avatar Jul 11 '17 11:07 ajbeaven

how to add tooltip directly on table row

roser240 avatar Jun 13 '18 07:06 roser240

https://github.com/mui-org/material-ui/issues/11601

afc163 avatar Jul 15 '18 05:07 afc163

I find a solution, maybe it helps. <Tooltip title="hhhh"> <Button href="" disabled> 删除 </Button> </Tooltip>

Adding an attribute "href".
According to https://ant.design/components/button-cn/#header <Button href="http://example.com">Hello world!</Button> 则会渲染为 <a href="http://example.com"><span>Hello world!</span></a>

Irislm avatar Jul 16 '18 05:07 Irislm

Workaround:

  1. Wrap the disabled button/input in another element.
  2. Add {pointer-events: none} style to the disabled button/input.

The solution requires both of these steps to work ^

jennifer-shehane avatar Aug 08 '18 16:08 jennifer-shehane

@jennifer-shehane is there a reason why this works? Or was it through trial and error?

sstern6 avatar Jan 05 '19 01:01 sstern6

Yeah, just trial and error. 😄

jennifer-shehane avatar Jan 07 '19 05:01 jennifer-shehane

+1

Hellowor1d avatar Oct 08 '19 10:10 Hellowor1d

+1

udielenberg avatar Feb 16 '20 15:02 udielenberg

+1

kah-eek avatar Mar 26 '20 22:03 kah-eek

Workaround:

  • Wrap the disabled button/input in another element.
  • Add { pointer-events: none; } style to the disabled button/input.
  • Set { cursor: not-allowed; } to the wrapper to fix cursor behavior that stops working with previous step (adding pointer-events: none;).
<Tooltip title="Tooltip Title">
  <span style={{ cursor: disabled ? 'not-allowed' : 'pointer' }}>
    <button disabled={disabled} style={{ pointerEvents: 'none' }}>
      button text
    </button>
  </span>
</Tooltip>

I've used @sandwich99's comment and @jennifer-shehane's workaround (big thanks!!)

@jennifer-shehane Correct me if I am wrong, but using your solution breaks the non-disabled state, the button stops showing cursor: pointer when active and not-allowed when disabled, I've extended the fix so it fully works for both disabled and non-disabled states.

itsmichaeldiego avatar Jun 29 '20 02:06 itsmichaeldiego

For those who cannot modify the or add a parent element:

  • Add { pointer-events: none; } style to the disabled button/input.
  • Add the not-allowed cursor to the button children.

For example:

.my-tooltip-class button.ant-btn[disabled] {
  pointer-events: none;

  &>* {
    pointer-events: auto;
    cursor: not-allowed;
  }
}

By disabling pointer-events on the button we also lose the desired not-allowed cursor; for most purposes we can provide a "good enough" fix for this by displaying the not-allowed cursor only on the children. Note that this means the cursor will not be displayed when the user hovers over the padding on the button. As the pointer-events rule is inherited by default, we must also switch it on for the children. Fortunately, this does not trigger the button mouseLeave bug.

benpryke avatar Sep 11 '20 19:09 benpryke

同样碰到这个问题。暂时用这样的方式解决了:

<span style={{display: 'inline-block', padding: 1, marginTop: -1}}>
    <button disabled>提交</button>
</span>

不知道有没有更好的办法

你这个方法,如果鼠标移开快一点的话,是不生效的;

Frank-MJ avatar Dec 07 '20 09:12 Frank-MJ

If any of you guys are using styled-components and typescript with react, then the following solution/work-around (which depends on the solution(s) from @itsmichaeldiego & @jennifer-shehane mentioned above) can be used:

import styled from 'styled-components';
import { Button, Tooltip } from 'antd';

const StyledButton = styled(Button)`
  pointer-events: ${({ disabled }) => disabled ? 'none' : 'auto'};
`;

const StyledButtonWrapper = styled.span`
  cursor: ${({ disabled } : { disabled: boolean }) => disabled ? 'not-allowed' : 'pointer'};
`;

interface BugFreeButtonWithTooltipInterface {
  disabled: boolean;
  // other props...
}

const BugFreeButtonWithTooltip: React.FC<BugFreeButtonWithTooltipInterface> = props => (
  <Tooltip placement="left" title="this is a bug free disabled/enabled button with tooltip">
    <StyledButtonWrapper disabled={props.disabled}>
      <StyledButton {...props} />
    </StyledButtonWrapper>
  </Tooltip>
);

export default BugFreeButtonWithTooltip;

Ch-sriram avatar Dec 08 '20 17:12 Ch-sriram

Workaround:

  1. Wrap the disabled button/input in another element.
  2. Add {pointer-events: none} style to the disabled button/input.

The solution requires both of these steps to work ^

thanks a lot! it really helps me

flysunshine avatar Jul 28 '22 03:07 flysunshine

Here is a workaround

<Tooltip title={!disabled ? "Tooltip" : null}> 
    <button
         type="primary"
         disabled={disabled}
     >
         Tooltip Button
     </button>
</Tooltip>

anjantalatam avatar Jul 21 '23 05:07 anjantalatam

I'm facing an issue with Tooltips not getting triggered when the InputPassword component is placed inside a Form and is disabled. The isLockedOrUnauthorized condition determines whether the InputPassword should be disabled or not. Unfortunately, when the input is disabled, the Tooltips do not show up upon hover, which prevents users from receiving additional information when their input is locked or unauthorized.

Steps to Reproduce:

  1. Create a Form containing a FormItem with a Tooltip wrapping an InputPassword component.
  2. Set the InputPassword component to be disabled.
  3. Observe that the Tooltips do not appear when hovering over the disabled InputPassword component.
  4. Additionally, try wrapping the InputPassword component in a div or span; this causes the form not to get submitted.

Expected Behavior: Tooltips should still be triggered when hovering over the disabled InputPassword component, providing relevant information to users even when the input is locked or unauthorized.

Code Snippet:

<FormItem>
  <Tooltip key={tooltipText}>
    <TooltipTrigger asChild>
        <InputPassword
          placeholder="SECRET"
          value={field.value}
          onChange={field.onChange}
        />
    </TooltipTrigger>
    <TooltipContent>
      <p className="first-letter:capitalize">{tooltipText}</p>
    </TooltipContent>
  </Tooltip>
  <FormMessage className="text-left" />
</FormItem>

Environment:

Browser version: Chrome Version 114.0.5735.198 (Official Build) (x86_64) Operating System: macOS Ventura 13.4.1 (c) Additional Notes: I have tested this issue on VSCode and confirmed the behavior described above.

Any insights or help on resolving this issue would be greatly appreciated. Thank you!

evybauer avatar Aug 02 '23 20:08 evybauer