Skip to content

Commit 3cd5ade

Browse files
CodySchaafoliviertassinari
authored andcommitted
[Slider] pr comments
1 parent 070e54d commit 3cd5ade

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

docs/src/pages/components/icons/icons-zh.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ import SvgIcon from '@material-ui/core/SvgIcon';
309309

310310
```jsx
311311
import Icon from '@material-ui/core/Icon';
312-
import { visuallyHidden } from '@material-ui/system';
312+
import { visuallyHidden } from '@material-ui/utils';
313313
import { makeStyles } from '@material-ui/core/styles';
314314

315315
const classes = makeStyles({ visuallyHidden })();

packages/material-ui-unstyled/src/SliderUnstyled/SliderUnstyled.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import {
99
unstable_useEventCallback as useEventCallback,
1010
unstable_useForkRef as useForkRef,
1111
unstable_useControlled as useControlled,
12+
visuallyHidden,
1213
} from '@material-ui/utils';
13-
import { visuallyHidden } from '@material-ui/system';
14+
1415
import isHostComponent from '../utils/isHostComponent';
1516
import sliderUnstyledClasses from './sliderUnstyledClasses';
1617
import SliderValueLabelUnstyled from './SliderValueLabelUnstyled';
@@ -20,6 +21,9 @@ function asc(a, b) {
2021
}
2122

2223
function clamp(value, min, max) {
24+
if (value == null) {
25+
return min;
26+
}
2327
return Math.min(Math.max(min, value), max);
2428
}
2529

@@ -221,7 +225,7 @@ const SliderUnstyled = React.forwardRef(function SliderUnstyled(props, ref) {
221225

222226
const [valueDerived, setValueState] = useControlled({
223227
controlled: valueProp,
224-
default: defaultValue,
228+
default: defaultValue ?? min,
225229
name: 'Slider',
226230
});
227231

@@ -689,7 +693,7 @@ const SliderUnstyled = React.forwardRef(function SliderUnstyled(props, ref) {
689693
disabled={disabled}
690694
value={values[index]}
691695
onChange={handleHiddenInputChange}
692-
style={{ ...visuallyHidden, direction: theme?.direction ?? 'ltr' }} // TODO is there a better way to do this using the utilityClasses object?
696+
style={{ ...visuallyHidden, direction: isRtl ? 'rtl' : 'ltr' }}
693697
/>
694698
<ValueLabelComponent
695699
valueLabelFormat={valueLabelFormat}

packages/material-ui-utils/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export { default as getDisplayName } from './getDisplayName';
88
export { default as HTMLElementType } from './HTMLElementType';
99
export { default as ponyfillGlobal } from './ponyfillGlobal';
1010
export { default as refType } from './refType';
11+
export { default as visuallyHidden } from './visuallyHidden';
1112
export { default as unstable_capitalize } from './capitalize';
1213
export { default as unstable_createChainedFunction } from './createChainedFunction';
1314
export { default as unstable_debounce } from './debounce';

packages/material-ui/src/Slider/Slider.test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -874,11 +874,9 @@ describe('<Slider />', () => {
874874

875875
expect(() => {
876876
setProps({ value: undefined });
877-
}).toErrorDev([
878-
// TODO Not sure if we should try and silence this warning or if it is ok to keep
879-
'Warning: Received NaN for the `value` attribute. If this is expected, cast the value to a string.',
877+
}).toErrorDev(
880878
'Material-UI: A component is changing the controlled value state of Slider to be uncontrolled.',
881-
]);
879+
);
882880
});
883881

884882
it('should warn when switching between uncontrolled to controlled', () => {

0 commit comments

Comments
 (0)