-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
[Slider] New Slider components and hook #373
Conversation
dd496d9
to
366c478
Compare
This comment was marked as resolved.
This comment was marked as resolved.
366c478
to
b1707f7
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
b4723a8
to
1c97949
Compare
Netlify deploy preview |
|
I've updated this so it announces "value" before "start/end range", it's announcing correctly as "slider" for me and not group though, I think this is just a VO quirk: range.mov
You mean when VO focuses on the Root and not the Thumb right? I don't think it's possible to get it to announce "slider" unless it explicitly has the slider role (which is obviously incorrect). It also doesn't announce "group" like that for me, it could also be a VO issue: single.mov
The scale prop enables a non-linear scale (a feature from Material UI): https://mui.com/material-ui/react-slider/#non-linear-scale |
@mj12albert Ok on the a11y stuff 👍 On |
packages/mui-base/src/Slider/SliderControl/SliderControl.test.tsx
Outdated
Show resolved
Hide resolved
rootRef, | ||
scale = Identity, | ||
step = 1, | ||
tabIndex, |
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.
tabIndex
seems unused
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.
@michaldudak tabIndex
in the return value here gets put into context and is used by the Thumb like this:
base-ui/packages/mui-base/src/Slider/Root/SliderRoot.test.tsx
Lines 1587 to 1590 in 55a30f7
it('can be removed from the tab sequence', () => { | |
render(<TestSlider tabIndex={-1} value={30} />); | |
expect(screen.getByRole('slider')).to.have.property('tabIndex', -1); | |
}); |
I suppose it could be passed straight from the SliderRoot
component into the context without going through the hook, what do you think?
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.
Yup, if it's not used by the hook, it shouldn't go there.
|
||
const handleRootRef = useForkRef(rootRef, sliderRef); | ||
|
||
const areValuesEqual = React.useCallback( |
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.
Is there any specific reason this is returned by the hook and not defined as a static function that takes two parameters to compare?
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.
@michaldudak The 2nd parameter (the "old" value to be compared against) would be the internal valueState
which is internal to useSliderRoot
, I opted to pass this function through the hook instead of passing valueState
as it seemed messier to pass 3 "values" through the hook - values
, percentageValues
, and valueState
) => React.ReactElement) | ||
| (React.ReactElement & { ref: React.Ref<Element> }) | ||
| keyof typeof defaultRenderFunctions; | ||
} |
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.
It should be possible anyway with the standard useComponentRenderer
, right?
render={(props) => <CustomThumb {...props}><SomeOtherComponent />{props.children}</SomeOtherComponent></CustomThumb>}
.
I suppose it would just require some changes to the short form of the render prop (render={<CustomThumb><SomeOtherComponent /></CustomThumb}
), to merge the children with internal children.
Not sure if I can explain it better than the docs but let me try 😓 : First set up a slider like this: (omitted subcomponents for simplicity) <Slider.Root min={5} step={1} max={10} defaultValue={5} /> The possible values are: Now we add the <Slider.Root min={5} step={1} max={10} defaultValue={5} scale={(value) => 2 ** value } /> So now the default value of Does this make sense? Maybe it's the name |
8d1c24b
to
fbe5ef1
Compare
@mj12albert I understand now, thanks for explaining. Let's remove this functionality+prop for now. |
OK I've removed it |
```jsx | ||
<Slider.Thumb | ||
render={(props, inputProps) => { | ||
const { children, ...rest } = props; |
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.
We might want to change the naming convention in the codebase for this, but for now since it's one of the only variations we have in the codebase, it's simpler to stick to it (it's simpler to do a mass codebase update all at once if we want to change this).
const { children, ...rest } = props; | |
const { children, ...other } = props; |
Done in 89821a4
(I found this variation from reading the docs in MUI X Charts initially, I then did a quick search in VS Code where my environment has all the codebase of the organization in the VS Code workspace, to see the codebase patterns, and I found this in Base UI too).
Closes #216
Closes #76
Closes #77
Preview
https://deploy-preview-373--base-ui.netlify.app/base-ui/react-slider/
Major changes
disableSwap
prop has been dropped as well.Control
subcomponent is added to represent the click/touch area of the slider. Previously this was combined with the root, butSlider.Root
in the new API is expected to contain theOutput
element and a label as wellrail
slot/component previously referred to the full length of the slider. This is now renamed to instead be theTrack
track
component referred to the filled portion of the slider "bar". This is now renamed to instead be theIndicator
input
element anymore, it's automatically wired to the corresponding thumb (aspan
by default), and allows for styling the thumb directly with:focus-visible
Mark
component/slot, and themarks
prop will be dropped. Marks will be reintroduced with a new API in [Slider] Support for marks #462step
prop defaults to1
and can no longer benull
.ValueLabel
slot/component and related features have been dropped. This can be implemented usingTooltip
as in this demoisRtl
prop is replaced withdirection: 'ltr' | 'rtl'
for consistencyminStepsBetweenValues
prop (default0
) is added to prevent thumb overlapscale
prop is deprecatedSummary
render
prop for the Thumb component is a special case that does not use standard utils, because we need to render a "hidden"<input>
element. As a function it provides an additionalinputProps
argument, and it also supports the shorthand syntax. Documented here.input
- it's kept as a child of the thumb (for now) because we could solve [Slider] Issues with adding focus-visible styles to the thumb slot #77 without actually having to move the inputDemos
The first 4 are also in the docs
<label>
&aria-labelledby
: https://deploy-preview-373--base-ui.netlify.app/experiments/slider/#with-labels