[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 |
| rootRef, | ||
| scale = Identity, | ||
| step = 1, | ||
| tabIndex, |
There was a problem hiding this comment.
@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
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.
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.
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.
@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.
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 |
|
@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.
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
disableSwapprop has been dropped as well.Controlsubcomponent is added to represent the click/touch area of the slider. Previously this was combined with the root, butSlider.Rootin the new API is expected to contain theOutputelement and a label as wellrailslot/component previously referred to the full length of the slider. This is now renamed to instead be theTracktrackcomponent referred to the filled portion of the slider "bar". This is now renamed to instead be theIndicatorinputelement anymore, it's automatically wired to the corresponding thumb (aspanby default), and allows for styling the thumb directly with:focus-visibleMarkcomponent/slot, and themarksprop will be dropped. Marks will be reintroduced with a new API in [slider] Support for marks #462stepprop defaults to1and can no longer benull.ValueLabelslot/component and related features have been dropped. This can be implemented usingTooltipas in this demoisRtlprop is replaced withdirection: 'ltr' | 'rtl'for consistencyminStepsBetweenValuesprop (default0) is added to prevent thumb overlapscaleprop is deprecatedSummary
renderprop 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 additionalinputPropsargument, 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