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

Switch inside of a Tooltip is not rendered correctly #440

Open
janmonschke opened this issue Apr 5, 2024 · 3 comments
Open

Switch inside of a Tooltip is not rendered correctly #440

janmonschke opened this issue Apr 5, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@janmonschke
Copy link

Description

When a Switch is rendered inside a Tooltip, the Switch's background color is not correct when it's unchecked.

Actual behaviour

Screenshot 2024-04-05 at 20 54 00 Screenshot 2024-04-05 at 20 54 10

Example code:

<Heading mb="2">Switch with a tooltip</Heading>
<Tooltip content="test tooltip content">
  <Switch defaultChecked={false} />
</Tooltip>
<Heading my="2">Switch without a tooltip</Heading>
<Switch defaultChecked={false} />

Codesandbox: https://codesandbox.io/p/sandbox/radix-themes-tooltip-switch-g7jgg5

Expected behaviour

The background color of the Switch inside the Tooltip matches the unchecked color of the standalone Switch.

Meta

  • Reproduced in latest Firefox and Chrome
  • Using @radix-ui/themes version 3.0.2 but was broken in 3.0.0 as well.
@henriquekio
Copy link

Hey,

Observing the inspector looks like it occurs because the CSS of the switch uses the data-state (checked | unchecked) attr as a selector, but, the Tooltip component replaces the data-state also (closed | delayed-open | instant-open).

Every time that you set a tooltip your first child will receive this attr (data-state), and in this case, this causes a conflict of styles.

I don't know if it's possible to replace this class selector to not watch the data-state attribute, and if this change, can hurt the accessibility principles of radix.

But you can quickly fix this using an ancestor in the switch component like a span element. Using this way, the data-state of the tooltip will change states on the ancestor element (span), and not will interfere with the data-state of the switch.

Codesandbox: https://codesandbox.io/p/sandbox/radix-themes-tooltip-switch-forked-qmlwq7

@janmonschke
Copy link
Author

Gotcha, the <span /> workaround is good enough for me at the moment. This should probably be mentioned in the docs though, wdyt?

@vladmoroz
Copy link
Contributor

@benoitgrelard do you know of a way around this issue?

@vladmoroz vladmoroz added the bug Something isn't working label Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants