[Slider] Modernize implementation#583
Conversation
Netlify deploy preview |
4293925 to
b595967
Compare
753b46c to
04e16b3
Compare
04e16b3 to
eff3fb8
Compare
eff3fb8 to
cf27b23
Compare
3d02250 to
f3e90f3
Compare
f3e90f3 to
5dadbbc
Compare
5dadbbc to
6f8e65f
Compare
michaldudak
left a comment
There was a problem hiding this comment.
It would be great if @atomiks could review the usage of the Composite component
| import * as React from 'react'; | ||
| import * as Slider from '@base_ui/react/Slider'; | ||
| import { useSliderContext } from '@base_ui/react/Slider'; | ||
| import { useSliderContext } from '../../../packages/mui-base/src/Slider/Root/SliderContext'; |
There was a problem hiding this comment.
If there is a legitimate use case for the context, we should export it from the package.
There was a problem hiding this comment.
We discussed this and decided to revisit exporting Context(s) after the alpha phase
| <Slider.Control className={classes.control}> | ||
| <Slider.Track className={classes.track}> | ||
| <Slider.Indicator className={classes.indicator} /> | ||
| <Slider.Thumb className={classes.thumb} inputId=":slider-thumb-input:" /> |
There was a problem hiding this comment.
The inputId prop is not documented
| /** | ||
| * @ignore - internal component. | ||
| */ | ||
| export const SliderContext = React.createContext<SliderRoot.Context | undefined>(undefined); |
There was a problem hiding this comment.
Context type should be defined in this file (and be called SliderContext)
There was a problem hiding this comment.
Updated ~ I've also renamed it to SliderRootContext/useSliderRootContext to match other components
There was a problem hiding this comment.
Yeah, that's actually what I meant 😅
491175e to
f16af45
Compare
f16af45 to
364fea9
Compare
|
|
||
| // Map with index (DOM position) as the key and the id attribute of each thumb <input> element as the value | ||
| const [inputIdMap, setInputMap] = React.useState(() => new Map<number, string>()); | ||
|
|
||
| const deregisterInputId = React.useCallback((index: number) => { | ||
| setInputMap((prevMap) => { | ||
| const nextMap = new Map(prevMap); | ||
| nextMap.delete(index); | ||
| return nextMap; | ||
| }); | ||
| }, []); | ||
|
|
||
| const registerInputId = React.useCallback( | ||
| (index: number, inputId: string | undefined) => { | ||
| if (index > -1 && inputId !== undefined) { | ||
| setInputMap((prevMap) => new Map(prevMap).set(index, inputId)); | ||
| } | ||
|
|
||
| return { | ||
| deregister: deregisterInputId, | ||
| }; | ||
| }, | ||
| [deregisterInputId], | ||
| ); |
There was a problem hiding this comment.
Is it possible to modify the Composite source to allow for metadata instead?
There was a problem hiding this comment.
Should be! How about doing this when refactoring Tabs to use Composite? Tabs uses metadata more extensively, and I wanted to get this PR merged ASAP to unblock the ESM work @michaldudak is doing 🙏
This reverts commit 48ed1ff.
Summary
useCompoundwithCompositePreviously the
idattribute of all theinputelements were passed touseCompoundas metadata to generate theforattribute of theoutputelement.However the refs provided by Composite can't be used during the render of
Outputfor this, so theids have to be held in a new state