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 is not triggered when `title` prop has value

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

Reproduction link

Edit on CodeSandbox

Steps to reproduce

  1. Go to https://codesandbox.io/s/vigorous-tesla-1ugd31?file=/src/App.js
  2. Type “x”
  3. You can see from the console.log() that the current title prop is undefined
  4. Type backspace to remove “x”
  5. From the console.log(), now the current title prop is "Required field"

What is expected?

The Tooltip should be displayed with the message Required field since at step 5 there are trigger="focus" and title="Required field" props on Tooltip.

What is actually happening?

Tooltip is not displayed

Environment Info
antd 4.18.8
React 17.0.2
System Mac OS 12.1
Browser Firefox 96

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
pobchcommented, Mar 11, 2022

Got it.

To workaround this issue, we need to implement isFocusing state and use it to control visible of Tooltip ourself. The following is my implementation, thanks @kanweiwei for the idea.

function InputWithTooltip({ onChange, value, errMsg }) {
  console.log("title =", errMsg);
  const [isFocusing, setIsFocusing] = useState(false);
  const visible = !!errMsg && isFocusing;
  return (
    <Tooltip
      placement="bottom"
      trigger="focus"
      title={errMsg}
      visible={visible}
    >
      <Input
        onChange={onChange}
        value={value}
        onFocus={() => {
          setIsFocusing(true);
        }}
        onBlur={() => {
          setIsFocusing(false);
        }}
      />
    </Tooltip>
  );
}

codesandbox: https://codesandbox.io/s/wonderful-vaughan-x3ovxd?file=/src/App.js

0reactions
zombieJcommented, Mar 11, 2022

@kanweiwei answer the question. trigger is trigger, dynamic change title do not trigger focus again since focus is only fire once when get focused.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Material UI tooltip doesn't display on custom component ...
As far as I can tell, I am doing about the simplest implementation of the tooltip component: I import it directly (no custom...
Read more >
React Tooltip component - Material UI - MUI
The tooltip is normally shown immediately when the user's mouse hovers over the element, and hides immediately when the user's mouse leaves. A...
Read more >
FAQ | Tippy.js - GitHub Pages
The title attribute should be removed once you have its content so the browser's default tooltip isn't displayed along with the tippy. #Plugin....
Read more >
rc-tooltip - npm
Start using rc-tooltip in your project by running `npm i rc-tooltip`. ... require('react-dom'); // By default, the tooltip has no style.
Read more >
Tooltip - React Spectrum Libraries - Adobe
The TooltipTrigger accepts exactly two children: the element which triggers the display of the Tooltip and the Tooltip itself. The trigger element must...
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