Skip to content

Conversation

@aworld1
Copy link

@aworld1 aworld1 commented Oct 8, 2025

Fixes #6765

Changes proposed in this pull request:

Added a new optional useHandleLabelPortal prop to SliderBaseProps that fixes an issue where slider handle labels (tooltips showing current values) get clipped when the slider is placed inside containers with overflow: 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:

  • Added ensureParentOverflowVisible?: boolean prop to SliderBaseProps interface (defaults to false for backward
    compatibility)
  • Modified Handle component to programmatically set parent container's overflow style to visible when the prop is enabled
  • Walks up the DOM tree from the slider element to find all ancestor elements with overflow: hidden/auto/scroll and
    temporarily modifies them
  • Stores original overflow values and restores them when the prop is disabled or component unmounts
  • Works with all slider variants (Slider, RangeSlider, MultiSlider) and both orientations (horizontal, vertical)

Files modified:

  • packages/core/src/components/slider/multiSlider.tsx - Added prop definition and default value
  • packages/core/src/components/slider/handle.tsx - Added DOM traversal logic to modify parent overflow styles

Screenshot

Screenshot 2025-10-09 at 8 47 32 PM

@changelog-app
Copy link

changelog-app bot commented Oct 8, 2025

Generate changelog in packages/core/changelog/@unreleased

Type (Select exactly one)

  • Feature (Adding new functionality)
  • Improvement (Improving existing functionality)
  • Fix (Fixing an issue with existing functionality)
  • Break (Creating a new major version by breaking public APIs)
  • Deprecation (Removing functionality in a non-breaking way)
  • Migration (Automatically moving data/functionality to a new system)

Description

Add useHandleLabelPortal prop to fix slider label clipping in overflow containers

Check the box to generate changelog(s)

  • Generate changelog entry

@svc-palantir-github
Copy link

prettier

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@svc-palantir-github
Copy link

lint

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@changelog-app
Copy link

changelog-app bot commented Oct 9, 2025

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)
Copy link
Contributor

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:

  1. Add className="bp6-slider-portal" to the Portal component
  2. Update the SCSS to target both .bp6-slider-handle .bp6-slider-label AND .bp6-slider-portal .bp6-slider-label with the shared styles
  3. 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>
Copy link
Contributor

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.

Screenshot 2025-10-09 at 14 01 43@2x

Perhaps we could use a method similar to the one we use in Popover with hasDarkParent:

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();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there are a few issues with using getBoundingClientRect() here for calculating label position. The positioning is only calculated once during render, but the handle position can change dynamically without triggering a re-render. For example, when scrolling or resizing the page:

Screenshot 2025-10-09 at 14 12 06

Screenshot 2025-10-09 at 14 11 30

*
* @default false
*/
useHandleLabelPortal?: boolean;
Copy link
Contributor

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%)",
Copy link
Contributor

Choose a reason for hiding this comment

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

Calculation seems to be a bit off here with respect to positioning the label next to a handle on a vertical Slider.

Screenshot 2025-10-09 at 14 24 56@2x

@svc-palantir-github
Copy link

new approach

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@aworld1 aworld1 changed the title Add useHandleLabelPortal prop to fix slider label clipping in overflow containers [FR] Add ensureParentOverflowVisible prop to prevent slider label clipping Oct 10, 2025
@aworld1
Copy link
Author

aworld1 commented Oct 10, 2025

@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 overflow: visible; on the container of the slider fixes this issue, however there is no way to force the user to make styling changes to their parent divs. So, I created a flag that programmatically sets the overflow properties of the parent, causing the handle to show through.

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).

@aworld1 aworld1 requested a review from ggdouglas October 10, 2025 00:51
@svc-palantir-github
Copy link

updated depth

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

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.

Slider popover in hidden overflow div

4 participants