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

Difficult to use button elements inside tooltip #249

Open
jfrankl opened this issue Feb 5, 2020 · 1 comment
Open

Difficult to use button elements inside tooltip #249

jfrankl opened this issue Feb 5, 2020 · 1 comment

Comments

@jfrankl
Copy link
Contributor

jfrankl commented Feb 5, 2020

I want to use a tooltip as though it is a dropdown. This seemed appropriate because Blaster does not have a dropdown component and effectively all of the functionality is the same.

Where I'm running into an issue is with including button elements in the tooltip. Because the tooltip needs to be nested in the element inside the component that triggers it, I end up with something that looks like this:

<Button>
  Open menu
  <Tooltip bg="white" trigger="click" placement="bottom-end" closeOnClickOutside>
    <Button appearance={Appearance.MINIMAL}>RCT Hub</Button>
    <Button appearance={Appearance.MINIMAL}>Logout</Button>
  </Tooltip>
</Button>

The resulting DOM is fine—the inner buttons are actually rendered outside of the outer buttons. But this code results in React warnings about nested buttons.

index.js:1446 Warning: validateDOMNesting(...): <button> cannot appear as a descendant of <button>.

It would be valuable if there were a different way to connect a tooltip to the trigger element. Or, if there were a dedicated dropdown component. Having a basic dropdown with buttons comes up on most of our applications (for example, needing to make a flyout/overflow menu with some actions inside).

@designmatty
Copy link
Contributor

designmatty commented Feb 5, 2020

A dropdown component is planned #29

If I remember correctly, the tooltip component currently renders within the HTML element in the DOM for which it's attached to. If you were to render your Button as a different HTML element other than a <button>, the warning would go away. You could achieve this with the as prop. https://styled-components.com/docs/api#as-polymorphic-prop

<Button as="div">
  Open menu
  <Tooltip bg="white" trigger="click" placement="bottom-end" closeOnClickOutside>
    <Button appearance={Appearance.MINIMAL}>RCT Hub</Button>
    <Button appearance={Appearance.MINIMAL}>Logout</Button>
  </Tooltip>
</Button>

Note this may require some additional aria attributes. But I'm not sure. You'd have to test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants