Repository navigation
Fix slider tooltip drawn under the next slider #4209
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,6 +54,37 @@ | |
| return {percentage, offset: thumbInBoundsOffset}; | ||
| }; | ||
|
|
||
| // Same box Radix measures on the thumb: 16px plus a 2px border on each side | ||
| const THUMB_OUTER_SIZE = 20; | ||
|
|
||
| // The inset Radix gives the span around a thumb, for content that has to | ||
| // follow a thumb without being inside it | ||
| export const getThumbInset = ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This repeats |
||
| value: number, | ||
| minMaxValues: {min_mark: number; max_mark: number}, | ||
| vertical: boolean, | ||
| reverse: boolean | ||
| ): React.CSSProperties => { | ||
| const percentage = convertValueToPercentage( | ||
| value, | ||
| minMaxValues.min_mark, | ||
| minMaxValues.max_mark | ||
| ); | ||
| const offset = getThumbInBoundsOffset( | ||
| THUMB_OUTER_SIZE, | ||
| percentage, | ||
| reverse ? -1 : 1 | ||
| ); | ||
| const startEdge = vertical | ||
| ? reverse | ||
| ? 'top' | ||
| : 'bottom' | ||
|
Check warning on line 81 in components/dash-core-components/src/utils/sliderRendering.tsx
|
||
| : reverse | ||
| ? 'right' | ||
| : 'left'; | ||
|
Check warning on line 84 in components/dash-core-components/src/utils/sliderRendering.tsx
|
||
| return {[startEdge]: `calc(${percentage}% + ${offset}px)`}; | ||
| }; | ||
|
|
||
| export const renderSliderMarks = ( | ||
| renderedMarks: SliderMarks, | ||
| vertical: boolean, | ||
|
|
||
There was a problem hiding this comment.
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:141fixes 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 ishalfSize * (1 - percent / 50), so JS only needs to set the percentage.