-
-
Notifications
You must be signed in to change notification settings - Fork 74
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] 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
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 would be great if @atomiks could review the usage of the Composite component
@@ -1,7 +1,7 @@ | |||
'use client'; | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is a legitimate use case for the context, we should export it from the package.
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inputId
prop is not documented
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.
Updated!
/** | ||
* @ignore - internal component. | ||
*/ | ||
export const SliderContext = React.createContext<SliderRoot.Context | undefined>(undefined); |
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.
Context type should be defined in this file (and be called SliderContext
)
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.
Updated ~ I've also renamed it to SliderRootContext
/useSliderRootContext
to match other components
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to modify the Composite
source to allow for metadata instead?
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.
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 🙏
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.
Seems ok to me as of now
This reverts commit 48ed1ff.
Summary
useCompound
withComposite
Previously the
id
attribute of all theinput
elements were passed touseCompound
as metadata to generate thefor
attribute of theoutput
element.However the refs provided by Composite can't be used during the render of
Output
for this, so theid
s have to be held in a new state