Skip to content

Fix slider tooltip drawn under the next slider - #4209

Open
omkar-334 wants to merge 2 commits into
plotly:devfrom
omkar-334:fix/slider-tooltip-under-next-slider
Open

omkar-334 wants to merge 2 commits into
plotly:devfrom
omkar-334:fix/slider-tooltip-under-next-slider

Conversation

@omkar-334

Copy link
Copy Markdown

Fixes #3632. Targets dev.

With two sliders stacked, the first one's tooltip was painted under the second slider.

The tooltip's z-index: 1000 had no effect outside its own slider, for two reasons:

  • .dash-slider-root had z-index: 0, so each slider was its own stacking context and the later one always won.
  • The tooltip was a child of the thumb, and Radix wraps each thumb in a transformed span, which is another stacking context.

I first tried lifting that Radix span with CSS. It fixed the case in the issue, but the next slider's thumb still showed through the tooltip when the two lined up, so I moved the tooltip out of the thumb instead.

Changes

  • The tooltip is now a sibling of the thumb, inside a .dash-slider-tooltip-anchor div that copies the thumb's box and position. Tooltip placement is unchanged (checked to the pixel for horizontal, reversed, range and vertical sliders).
  • The root no longer sets z-index. The anchor has z-index: 1, or 2 while its thumb is hovered or focused. Both stay well below the dropdown and date picker popups (500).
  • The tooltip ignores the pointer, so a thumb that ends up under another slider's tooltip can still be dragged.
  • The anchor is aria-hidden, to match the old behaviour where the tooltip sat inside role="slider".

One visible side effect: the tooltip no longer scales up with the thumb on hover.

Not covered

A disabled slider still has the bug, because opacity on its root is a stacking context as well. Fixing it changes how every disabled slider is blended, so I left it for a follow-up. Happy to add it here if you prefer.

Testing

  • test_slsl021_tooltip_above_next_slider checks that nothing is painted over the tooltip: next slider's thumb right under it, range slider, hover, keyboard focus, and a slider inside a form.
  • test_slsl022_tooltip_follows_thumb checks that the anchor matches the thumb's rectangle in every orientation.

Both fail on dev and pass with this change. The rest of tests/integration/sliders passes locally.

Contributor Checklist

  • This PR targets dev (fix or chore) or next (feature, new API, breaking change), see Which branch to target
  • I have broken down my PR scope into the following TODO tasks
    • Render the slider tooltip as a sibling of the thumb
    • Stop the slider root from being a stacking context
    • Keep hover and focus tooltips working, including inside a form
  • I have run the tests locally and they passed. (refer to testing section in contributing)
  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR

optionals

  • I have added entry in the CHANGELOG.md

The tooltip was a child of the thumb. Radix wraps each thumb in a transformed span, and the slider root had z-index: 0, so the tooltip could not be drawn above a slider placed after it.

Render the tooltip as a sibling of the thumb, in an anchor that copies the thumb's box and position, and stop making the root a stacking context.

Fixes plotly#3632
@sonarqubecloud

Copy link
Copy Markdown

@omkar-334

omkar-334 commented Nov 27, 2026 •

Copy link
Copy Markdown
Author

First slider in focus, at a different point
Screenshot 2026-11-27 at 3 47 16 PM
First slider in focus, at the same point
Screenshot 2026-11-27 at 3 47 23 PM
Second slider in focus, at the same point
Screenshot 2026-11-27 at 3 47 28 PM

@T4rk1n T4rk1n left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix is right. Dropping the root z-index and pulling the tooltip out of Radix's transformed span is the only way to get it above the next slider, and I checked the sibling selectors against Radix 1.6.1 (wrapper span, then the input only in a form). slsl021 will catch it if a Radix bump changes that structure. Tests are good. Nothing here blocks merge.

The one thing I'd like addressed is the hardcoded thumb size, since the anchor now guesses the thumb's box where the tooltip used to follow the real one. Details inline. Leaving the disabled case for a follow-up is fine, can you open an issue for it so it doesn't get lost?

};

// Same box Radix measures on the thumb: 16px plus a 2px border on each side
const THUMB_OUTER_SIZE = 20;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Radix measures the real thumb and uses that size for the offset. This uses a fixed 20, and sliders.css:141 fixes the anchor box at 16px plus border too. If an app makes the thumb bigger (.dash-slider-thumb { width: 24px; height: 24px }), the tooltip is no longer centered on the thumb and drifts more near min and max. Before, the tooltip followed whatever the thumb was. Can you drive both the thumb and the anchor from one CSS variable? The offset can live in CSS as well: Radix's formula is halfSize * (1 - percent / 50), so JS only needs to set the percentage.


// The inset Radix gives the span around a thumb, for content that has to
// follow a thumb without being inside it
export const getThumbInset = (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This repeats getRadixThumbPosition a few lines up, plus direction and size. Can you extend that one with size and direction params instead of adding a second copy?

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

Successfully merging this pull request may close these issues.

[BUG] Tooltip zindex incorrect on overlapping sliders

2 participants