mui / mui/base-ui

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

Open
#4,038 3 comments 0 reactions 0 assignees View on GitHub
component: slider support: question
Dominant language
TypeScript
Stars
10.9k
Forks
543
Avg merge
1d 20h
Merged PRs (30d)
101

Description

# 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 }` ?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.