Skip to content
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] Apply the disabled pseudo class on the thumb too #18011

Merged
merged 3 commits into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/pages/api/slider.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Any other props supplied will be provided to the root element (native element).
| <span class="prop-name">colorSecondary</span> | <span class="prop-name">.MuiSlider-colorSecondary</span> | Styles applied to the root element if `color="secondary"`.
| <span class="prop-name">marked</span> | <span class="prop-name">.MuiSlider-marked</span> | Styles applied to the root element if `marks` is provided with at least one label.
| <span class="prop-name">vertical</span> | <span class="prop-name">.MuiSlider-vertical</span> | Pseudo-class applied to the root element if `orientation="vertical"`.
| <span class="prop-name">disabled</span> | <span class="prop-name">.Mui-disabled</span> | Pseudo-class applied to the root element if `disabled={true}`.
| <span class="prop-name">disabled</span> | <span class="prop-name">.Mui-disabled</span> | Pseudo-class applied to the root and thumb element if `disabled={true}`.
| <span class="prop-name">rail</span> | <span class="prop-name">.MuiSlider-rail</span> | Styles applied to the rail element.
| <span class="prop-name">track</span> | <span class="prop-name">.MuiSlider-track</span> | Styles applied to the track element.
| <span class="prop-name">trackFalse</span> | <span class="prop-name">.MuiSlider-trackFalse</span> | Styles applied to the track element if `track={false}`.
Expand Down
19 changes: 6 additions & 13 deletions packages/material-ui/src/Slider/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export const styles = theme => ({
// Remove grey highlight
WebkitTapHighlightColor: 'transparent',
'&$disabled': {
pointerEvents: 'none',
cursor: 'default',
color: theme.palette.grey[400],
},
Expand Down Expand Up @@ -172,7 +173,7 @@ export const styles = theme => ({
},
/* Pseudo-class applied to the root element if `orientation="vertical"`. */
vertical: {},
/* Pseudo-class applied to the root element if `disabled={true}`. */
/* Pseudo-class applied to the root and thumb element if `disabled={true}`. */
disabled: {},
/* Styles applied to the rail element. */
rail: {
Expand Down Expand Up @@ -244,8 +245,7 @@ export const styles = theme => ({
'&$active': {
boxShadow: `0px 0px 0px 14px ${fade(theme.palette.primary.main, 0.16)}`,
},
'$disabled &': {
pointerEvents: 'none',
'&$disabled': {
width: 8,
height: 8,
marginLeft: -4,
Expand All @@ -258,7 +258,7 @@ export const styles = theme => ({
marginLeft: -5,
marginBottom: -6,
},
'$vertical$disabled &': {
'$vertical &$disabled': {
marginLeft: -3,
marginBottom: -4,
},
Expand Down Expand Up @@ -617,10 +617,6 @@ const Slider = React.forwardRef(function Slider(props, ref) {
});

React.useEffect(() => {
if (disabled) {
return () => {};
}

const { current: slider } = sliderRef;
slider.addEventListener('touchstart', handleTouchStart);

Expand All @@ -632,7 +628,7 @@ const Slider = React.forwardRef(function Slider(props, ref) {
document.body.removeEventListener('touchmove', handleTouchMove);
document.body.removeEventListener('touchend', handleTouchEnd);
};
}, [disabled, handleMouseEnter, handleTouchEnd, handleTouchMove, handleTouchStart]);
}, [handleMouseEnter, handleTouchEnd, handleTouchMove, handleTouchStart]);

if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line react-hooks/rules-of-hooks
Expand All @@ -658,10 +654,6 @@ const Slider = React.forwardRef(function Slider(props, ref) {
onMouseDown(event);
}

if (disabled) {
return;
}

event.preventDefault();
const finger = trackFinger(event, touchId);
const { newValue, activeIndex } = getFingerNewValue({ finger, values, source: valueDerived });
Expand Down Expand Up @@ -764,6 +756,7 @@ const Slider = React.forwardRef(function Slider(props, ref) {
<ThumbComponent
className={clsx(classes.thumb, classes[`thumbColor${capitalize(color)}`], {
[classes.active]: active === index,
[classes.disabled]: disabled,
[classes.focusVisible]: focusVisible === index,
})}
tabIndex={disabled ? null : 0}
Expand Down