Skip to content

Commit

Permalink
[Slider] Miscellaneous improvements (mui#35941)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeeshanTamboli authored and siriwatknp committed Feb 23, 2023
1 parent 1060372 commit bad09ac
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 47 deletions.
5 changes: 1 addition & 4 deletions packages/mui-joy/src/Slider/Slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ import {
unstable_capitalize as capitalize,
} from '@mui/utils';
import { OverridableComponent } from '@mui/types';
import useSlider from '@mui/base/useSlider';
import useSlider, { valueToPercent } from '@mui/base/useSlider';
import { isHostComponent } from '@mui/base/utils';
import { useThemeProps, styled, Theme } from '../styles';
import { useColorInversion } from '../styles/ColorInversion';
import useSlot from '../utils/useSlot';
import sliderClasses, { getSliderUtilityClass } from './sliderClasses';
import { SliderTypeMap, SliderOwnerState } from './SliderProps';

const valueToPercent = (value: number, min: number, max: number) =>
((value - min) * 100) / (max - min);

function Identity(x: any) {
return x;
}
Expand Down
83 changes: 40 additions & 43 deletions packages/mui-material/src/Slider/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
useSlotProps,
unstable_composeClasses as composeClasses,
} from '@mui/base';
import useSlider from '@mui/base/useSlider';
import useSlider, { valueToPercent } from '@mui/base/useSlider';
import { alpha, lighten, darken } from '@mui/system';
import useThemeProps from '../styles/useThemeProps';
import styled, { slotShouldForwardProp } from '../styles/styled';
Expand All @@ -17,8 +17,6 @@ import capitalize from '../utils/capitalize';
import SliderValueLabel from './SliderValueLabel';
import sliderClasses, { getSliderUtilityClass } from './sliderClasses';

const valueToPercent = (value, min, max) => ((value - min) * 100) / (max - min);

function Identity(x) {
return x;
}
Expand Down Expand Up @@ -739,49 +737,48 @@ const Slider = React.forwardRef(function Slider(inputProps, ref) {
const ValueLabelComponent = valueLabelDisplay === 'off' ? Forward : ValueLabelSlot;

return (
<React.Fragment key={index}>
{/* TODO v6: Change component structure. It will help in avoiding the complicated React.cloneElement API added in SliderValueLabel component. Should be: Thumb -> Input, ValueLabel. Follow Joy UI's Slider structure. */}
<ValueLabelComponent
{...(!isHostComponent(ValueLabelComponent) && {
valueLabelFormat,
valueLabelDisplay,
value:
typeof valueLabelFormat === 'function'
? valueLabelFormat(scale(value), index)
: valueLabelFormat,
index,
open: open === index || active === index || valueLabelDisplay === 'on',
disabled,
/* TODO v6: Change component structure. It will help in avoiding the complicated React.cloneElement API added in SliderValueLabel component. Should be: Thumb -> Input, ValueLabel. Follow Joy UI's Slider structure. */
<ValueLabelComponent
key={index}
{...(!isHostComponent(ValueLabelComponent) && {
valueLabelFormat,
valueLabelDisplay,
value:
typeof valueLabelFormat === 'function'
? valueLabelFormat(scale(value), index)
: valueLabelFormat,
index,
open: open === index || active === index || valueLabelDisplay === 'on',
disabled,
})}
{...valueLabelProps}
>
<ThumbSlot
data-index={index}
{...thumbProps}
className={clsx(classes.thumb, thumbProps.className, {
[classes.active]: active === index,
[classes.focusVisible]: focusedThumbIndex === index,
})}
{...valueLabelProps}
style={{
...style,
pointerEvents: disableSwap && active !== index ? 'none' : undefined,
...thumbProps.style,
}}
>
<ThumbSlot
<InputSlot
data-index={index}
{...thumbProps}
className={clsx(classes.thumb, thumbProps.className, {
[classes.active]: active === index,
[classes.focusVisible]: focusedThumbIndex === index,
})}
style={{
...style,
pointerEvents: disableSwap && active !== index ? 'none' : undefined,
...thumbProps.style,
}}
>
<InputSlot
data-index={index}
aria-label={getAriaLabel ? getAriaLabel(index) : ariaLabel}
aria-valuenow={scale(value)}
aria-labelledby={ariaLabelledby}
aria-valuetext={
getAriaValueText ? getAriaValueText(scale(value), index) : ariaValuetext
}
value={values[index]}
{...inputSliderProps}
/>
</ThumbSlot>
</ValueLabelComponent>
</React.Fragment>
aria-label={getAriaLabel ? getAriaLabel(index) : ariaLabel}
aria-valuenow={scale(value)}
aria-labelledby={ariaLabelledby}
aria-valuetext={
getAriaValueText ? getAriaValueText(scale(value), index) : ariaValuetext
}
value={values[index]}
{...inputSliderProps}
/>
</ThumbSlot>
</ValueLabelComponent>
);
})}
</RootSlot>
Expand Down

0 comments on commit bad09ac

Please sign in to comment.