Code Monkey home page Code Monkey logo

Comments (9)

atomiks avatar atomiks commented on May 11, 2024 1

I think it's fixed in the latest version

from tippyjs-react.

KubaJastrz avatar KubaJastrz commented on May 11, 2024

Not sure what you're trying to achieve. Do you want tippy around a <label> or #targetElement?

from tippyjs-react.

atomiks avatar atomiks commented on May 11, 2024

I'm guessing you're trying to use a focus trigger? You need to set hideOnClick={false} in that case.

from tippyjs-react.

benkeen avatar benkeen commented on May 11, 2024

Apologies! This was poorly explained on my part.

I was just updating to Tippy from an older tooltip lib and had the following markup structure where the tippy was inside a label. It's unrelated semantically and has nothing to do with the label - it just happened to exist within it.

I've done a little digging and found that this works fine. The tip appears when clicking the button.

<div>
    <label htmlFor="field">
        Label here.
        <Tippy content="Infotip." placement="right" zIndex={19998} trigger="click">
            <button>Click me.</span>
        </Tippy>
    </label>
    <input type="text" id="field" />
</div>

But when you change the button element to a span, the tippy no longer appears.

If you leave it as a span, but remove the htmlFor attribute on the label, the tooltip then appears again.

Not sure if that's expected behaviour?

from tippyjs-react.

atomiks avatar atomiks commented on May 11, 2024

But when you change the button element to a span, the tippy no longer appears.

Right, I think we should account for this. Currently there's no check if children changed to recreate the instance.

Want to make a PR?

from tippyjs-react.

benkeen avatar benkeen commented on May 11, 2024

Actually I think this isn't to do with the children changing (but that's an interesting clause!), it just doesn't seem to trigger at all with a span. Refreshing the page with the span as the dom node & the tip doesn't show up.

from tippyjs-react.

atomiks avatar atomiks commented on May 11, 2024

I can reproduce that on CodeSandbox. I think it has something to do with the focus instantly switching to the input (upon clicking the <span>). Using hideOnClick="toggle" seems to fix it...

https://codesandbox.io/s/nl3nn2n2p

from tippyjs-react.

benkeen avatar benkeen commented on May 11, 2024

I think it has something to do with the focus instantly switching to the input

Yeah, that sounds likely. I wonder if it would be more standard behaviour to prevent the bubbling to occur here so it doesn't focus? - or just preventing the focus event affecting the tip.

But thanks for the workaround.

from tippyjs-react.

benkeen avatar benkeen commented on May 11, 2024

btw, as a workaround which enabled me to keep the desired clicking behaviour, I simply used a button and styled it appropriately. That element prevents it from focusing on the input field & all is well. Thanks again!

from tippyjs-react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.