-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[FR] Add ensureParentOverflowVisible prop to prevent slider label clipping #7585
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: develop
Are you sure you want to change the base?
Conversation
Generate changelog in
|
prettierBuild artifact links for this commit: documentation | landing | table | demoThis is an automated comment from the deploy-preview CircleCI job. |
lintBuild artifact links for this commit: documentation | landing | table | demoThis is an automated comment from the deploy-preview CircleCI job. |
✅ Successfully generated changelog entry!What happened?Your changelog entries have been stored in the database as part of our migration to ChangelogV3. Need to regenerate?Simply interact with the changelog bot comment again to regenerate these entries. |
| // Also include the styling that would normally come from .bp5-slider-handle .bp5-slider-label | ||
| const style: React.CSSProperties = vertical | ||
| ? { | ||
| // Tooltip-like styling from SCSS (lines 141-157 in _slider.scss) |
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.
I'm not a fan of duplicating all those inline styles from .bp6-slider-label. The two implementations could drift apart pretty easily. How about we add a class to the portal (something like .bp6-slider-portal) to handle the majority of these styles via the existing class instead?
The idea:
- Add
className="bp6-slider-portal"to the Portal component - Update the SCSS to target both
.bp6-slider-handle .bp6-slider-labelAND.bp6-slider-portal .bp6-slider-labelwith the shared styles - Keep only the positioning stuff (position, top, left, transform) as inline styles since those need to be calculated on the fly
| <span className={Classes.SLIDER_LABEL} style={style}> | ||
| {label} | ||
| </span> | ||
| </Portal> |
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.
Since we're using a portal, we unfortunately also lose the .bp6-dark class scope that gives the label styles in dark mode. I think we should probably address this.
Perhaps we could use a method similar to the one we use in Popover with hasDarkParent:
blueprint/packages/core/src/components/popover/popover.tsx
Lines 700 to 705 in 031a998
| private updateDarkParent() { | |
| if (this.props.usePortal && this.state.isOpen) { | |
| const hasDarkParent = this.targetRef.current?.closest(`.${Classes.DARK}`) != null; | |
| this.setState({ hasDarkParent }); | |
| } | |
| } |
| } | ||
|
|
||
| // Calculate the position of the label based on the handle's current position | ||
| const handleRect = this.handleElement.getBoundingClientRect(); |
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.
| * | ||
| * @default false | ||
| */ | ||
| useHandleLabelPortal?: 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.
Can we add this prop to the Slider component docs example? This would make it easier to review/test this change.
| padding: "4px 8px", | ||
| position: "fixed", | ||
| top: `${handleRect.top + handleRect.height / 2}px`, | ||
| transform: "translateY(-50%)", |
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.
new approachBuild artifact links for this commit: documentation | landing | table | demoThis is an automated comment from the deploy-preview CircleCI job. |
|
@ggdouglas I have made some changes to make this severely less complicated. Instead of using portals, which proved to be exceptionally challenging to mimic the example formatting that we had for the slider handle's existing styling, I went with a CSS trick that does the job. I noticed that I have temporarily modified the docs to show a section that contains a demo of this directly, which can be removed pre-merge (see screenshot in PR description). |
updated depthBuild artifact links for this commit: documentation | landing | table | demoThis is an automated comment from the deploy-preview CircleCI job. |



Fixes #6765
Changes proposed in this pull request:
Added a new optional
useHandleLabelPortalprop toSliderBasePropsthat fixes an issue where slider handle labels (tooltips showing current values) get clipped when the slider is placed inside containers withoverflow: hidden. This is particularly problematic with sliders that have large min/max ranges (e.g., -1,000,000 to 1,000,000) where the label text is wide.Technical implementation:
ensureParentOverflowVisible?: booleanprop toSliderBasePropsinterface (defaults tofalsefor backwardcompatibility)
overflow: hidden/auto/scrollandtemporarily modifies them
Slider,RangeSlider,MultiSlider) and both orientations (horizontal, vertical)Files modified:
packages/core/src/components/slider/multiSlider.tsx- Added prop definition and default valuepackages/core/src/components/slider/handle.tsx- Added DOM traversal logic to modify parent overflow stylesScreenshot