Skip to content

[slider] Targeting the Thumb properly in a Jest/Vitest environment #4038

@Powerplex

Description

@Powerplex

Get help

Ask a question

Developers using our Base UI based design system were confused as to why in order to select a Slider.Thumb in a test, one must use { hidden: true }:

expect(screen.getByRole('slider', { hidden: true })).toBeInTheDocument()

I noticed these lines must be the cause: https://github.com/mui/base-ui/blob/master/packages/react/src/slider/thumb/SliderThumb.tsx#L251-L254

return {
      ['--position' as string]: `${positionPercent}%`,
      visibility:
        (renderBeforeHydration && !isMounted) || positionPercent === undefined
          ? 'hidden'
          : undefined,

I can't explain why this condition exists and if there is a way around this to keep our tests clean (and avoid using { hidden: true } ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: sliderChanges related to the slider component.support: questionCommunity support but can be turned into an improvement.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions