Skip to content
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

Tippy within <label> with htmlFor prop doesn't show tooltip #51

Closed
benkeen opened this issue Feb 13, 2019 · 9 comments
Closed

Tippy within <label> with htmlFor prop doesn't show tooltip #51

benkeen opened this issue Feb 13, 2019 · 9 comments

Comments

@benkeen
Copy link
Contributor

benkeen commented Feb 13, 2019

When embedding my Tippy within a label that has an htmlFor attribute, the tippy doesn't show up. Looking at the DOM, I think it's adding then removing the tippy with a single click.

<label htmlFor="targetElement">
    Text here.
     <Tippy ... />
</label>
@benkeen benkeen changed the title Tippy within label with htmlFor shows then hides immediately Tippy within <label> with htmlFor props doesn't show tooltip Feb 13, 2019
@benkeen benkeen changed the title Tippy within <label> with htmlFor props doesn't show tooltip Tippy within <label> with htmlFor prop doesn't show tooltip Feb 13, 2019
@KubaJastrz
Copy link
Contributor

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

@atomiks
Copy link
Owner

atomiks commented Feb 13, 2019

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

@benkeen
Copy link
Contributor Author

benkeen commented Feb 13, 2019

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?

@atomiks
Copy link
Owner

atomiks commented Feb 13, 2019

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?

@benkeen
Copy link
Contributor Author

benkeen commented Feb 13, 2019

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.

@atomiks
Copy link
Owner

atomiks commented Feb 13, 2019

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

@benkeen
Copy link
Contributor Author

benkeen commented Feb 13, 2019

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.

@benkeen
Copy link
Contributor Author

benkeen commented Feb 13, 2019

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!

@atomiks
Copy link
Owner

atomiks commented Feb 7, 2020

I think it's fixed in the latest version

@atomiks atomiks closed this as completed Feb 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants