Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
38 changes: 0 additions & 38 deletions docs/src/pages/lab/slider/ReverseSlider.js

This file was deleted.

1 change: 0 additions & 1 deletion docs/src/pages/lab/slider/VerticalSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class VerticalSlider extends React.Component {
return (
<div className={classes.root}>
<Slider value={value} onChange={this.handleChange} vertical />
<Slider value={value} onChange={this.handleChange} vertical reverse />
</div>
);
}
Expand Down
5 changes: 4 additions & 1 deletion docs/src/pages/lab/slider/slider.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ Sliders reflect the current state of the settings they control.

## Reverse slider
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not remove this section all together?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about people looking for the missing prop but the changelog entry and this PR is probably sufficient.


{{"demo": "pages/lab/slider/ReverseSlider.js"}}
Per [material-design specification](https://material.io/design/components/sliders.html#usage)
the position of the minimum value should depend on the language direction: On the left for left-to-right
and on the right for right-to-left languages. Check the [Right-to-left guide](/guides/right-to-left/)
to learn how to switch to right-to-left languages.

## Custom thumb

Expand Down
2 changes: 0 additions & 2 deletions packages/material-ui-lab/src/Slider/Slider.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { TransitionHandlerProps } from '@material-ui/core/transitions/transition
export interface SliderProps
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, SliderClassKey, 'onChange'> {
disabled?: boolean;
reverse?: boolean;
vertical?: boolean;
max?: number;
min?: number;
Expand All @@ -29,7 +28,6 @@ export type SliderClassKey =
| 'activated'
| 'disabled'
| 'vertical'
| 'reverse'
| 'jumped';

declare const Slider: React.ComponentType<SliderProps>;
Expand Down
35 changes: 13 additions & 22 deletions packages/material-ui-lab/src/Slider/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const styles = theme => {
};

const commonTransitions = theme.transitions.create(
['width', 'height', 'left', 'top', 'box-shadow'],
['width', 'height', 'left', 'right', 'top', 'box-shadow'],
commonTransitionsOptions,
);
// no transition on the position
Expand Down Expand Up @@ -44,12 +44,6 @@ export const styles = theme => {
height: '100%',
padding: '8px 16px',
},
'&$reverse': {
transform: 'scaleX(-1)',
},
'&$vertical$reverse': {
transform: 'scaleY(-1)',
},
},
/* Styles applied to the container element. */
container: {
Expand Down Expand Up @@ -130,8 +124,6 @@ export const styles = theme => {
height: 'inherit',
width: 'inherit',
},
/* Class applied to the root element to trigger JSS nested styles if `reverse={true}`. */
reverse: {},
/* Class applied to the track and thumb elements to trigger JSS nested styles if `disabled`. */
disabled: {},
/* Class applied to the track and thumb elements to trigger JSS nested styles if `jumped`. */
Expand Down Expand Up @@ -177,15 +169,15 @@ function getMousePosition(event) {
};
}

function calculatePercent(node, event, isVertical, isReverted) {
function calculatePercent(node, event, isVertical, isRtl) {
const { width, height } = node.getBoundingClientRect();
const { top, left } = getOffset(node);
const { x, y } = getMousePosition(event);

const value = isVertical ? y - top : x - left;
const onePercent = (isVertical ? height : width) / 100;

return isReverted ? 100 - clamp(value / onePercent) : clamp(value / onePercent);
return isRtl && !isVertical ? 100 - clamp(value / onePercent) : clamp(value / onePercent);
}

function preventPageScrolling(event) {
Expand Down Expand Up @@ -275,8 +267,8 @@ class Slider extends React.Component {
};

handleClick = event => {
const { min, max, vertical, reverse } = this.props;
const percent = calculatePercent(this.containerRef, event, vertical, reverse);
const { min, max, vertical } = this.props;
const percent = calculatePercent(this.containerRef, event, vertical, this.isReverted());
const value = percentToValue(percent, min, max);

this.emitChange(event, value, () => {
Expand Down Expand Up @@ -320,8 +312,8 @@ class Slider extends React.Component {
};

handleMouseMove = event => {
const { min, max, vertical, reverse } = this.props;
const percent = calculatePercent(this.containerRef, event, vertical, reverse);
const { min, max, vertical } = this.props;
const percent = calculatePercent(this.containerRef, event, vertical, this.isReverted());
const value = percentToValue(percent, min, max);

this.emitChange(event, value);
Expand Down Expand Up @@ -383,6 +375,10 @@ class Slider extends React.Component {
});
}

isReverted() {
return this.props.theme.direction === 'rtl';
}

render() {
const { currentState } = this.state;
const {
Expand All @@ -396,7 +392,6 @@ class Slider extends React.Component {
onChange,
onDragEnd,
onDragStart,
reverse,
step,
theme,
value,
Expand All @@ -417,7 +412,6 @@ class Slider extends React.Component {
classes.root,
{
[classes.vertical]: vertical,
[classes.reverse]: reverse,
[classes.disabled]: disabled,
},
classNameProp,
Expand All @@ -436,7 +430,8 @@ class Slider extends React.Component {
});

const trackProperty = vertical ? 'height' : 'width';
const thumbProperty = vertical ? 'top' : 'left';
const horizontalMinimumPosition = theme.direction === 'ltr' ? 'left' : 'right';
const thumbProperty = vertical ? 'top' : horizontalMinimumPosition;
const inlineTrackBeforeStyles = { [trackProperty]: this.calculateTrackBeforeStyles(percent) };
const inlineTrackAfterStyles = { [trackProperty]: this.calculateTrackAfterStyles(percent) };
const inlineThumbStyles = { [thumbProperty]: `${percent}%` };
Expand Down Expand Up @@ -537,10 +532,6 @@ Slider.propTypes = {
* Callback function that is fired when the slider has begun to move.
*/
onDragStart: PropTypes.func,
/**
* If `true`, the slider will be reversed.
*/
reverse: PropTypes.bool,
/**
* The granularity the slider can step through values.
*/
Expand Down
17 changes: 0 additions & 17 deletions packages/material-ui-lab/src/Slider/Slider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,6 @@ describe('<Slider />', () => {
});
});

describe('prop: reverse', () => {
it('should render with the default and reverse classes', () => {
const wrapper = shallow(<Slider reverse value={0} />);
assert.strictEqual(wrapper.hasClass(classes.root), true);
assert.strictEqual(wrapper.hasClass(classes.reverse), true);
});
});

describe('props: vertical & reverse', () => {
it('should render with the default, reverse and vertical classes', () => {
const wrapper = shallow(<Slider reverse vertical value={0} />);
assert.strictEqual(wrapper.hasClass(classes.root), true);
assert.strictEqual(wrapper.hasClass(classes.reverse), true);
assert.strictEqual(wrapper.hasClass(classes.vertical), true);
});
});

describe('prop: disabled', () => {
const handleChange = spy();
let wrapper;
Expand Down
2 changes: 0 additions & 2 deletions pages/lab/api/slider.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import Slider from '@material-ui/lab/Slider';
| <span class="prop-name">onChange</span> | <span class="prop-type">func |   | Callback function that is fired when the slider's value changed. |
| <span class="prop-name">onDragEnd</span> | <span class="prop-type">func |   | Callback function that is fired when the slide has stopped moving. |
| <span class="prop-name">onDragStart</span> | <span class="prop-type">func |   | Callback function that is fired when the slider has begun to move. |
| <span class="prop-name">reverse</span> | <span class="prop-type">bool |   | If `true`, the slider will be reversed. |
| <span class="prop-name">step</span> | <span class="prop-type">number |   | The granularity the slider can step through values. |
| <span class="prop-name">thumb</span> | <span class="prop-type">element |   | The component used for the slider icon. This is optional, if provided should be a react element. |
| <span class="prop-name required">value *</span> | <span class="prop-type">number |   | The value of the slider. |
Expand All @@ -51,7 +50,6 @@ This property accepts the following keys:
| <span class="prop-name">thumb</span> | Styles applied to the thumb element.
| <span class="prop-name">thumbIconWrapper</span> | Class applied to the thumb element if custom thumb icon provided.
| <span class="prop-name">thumbIcon</span> |
| <span class="prop-name">reverse</span> | Class applied to the root element to trigger JSS nested styles if `reverse={true}`.
| <span class="prop-name">disabled</span> | Class applied to the track and thumb elements to trigger JSS nested styles if `disabled`.
| <span class="prop-name">jumped</span> | Class applied to the track and thumb elements to trigger JSS nested styles if `jumped`.
| <span class="prop-name">focused</span> | Class applied to the track and thumb elements to trigger JSS nested styles if `focused`.
Expand Down
7 changes: 0 additions & 7 deletions pages/lab/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ module.exports = require('fs')
raw: preval`
module.exports = require('fs')
.readFileSync(require.resolve('docs/src/pages/lab/slider/VerticalSlider'), 'utf8')
`,
},
'pages/lab/slider/ReverseSlider.js': {
js: require('docs/src/pages/lab/slider/ReverseSlider').default,
raw: preval`
module.exports = require('fs')
.readFileSync(require.resolve('docs/src/pages/lab/slider/ReverseSlider'), 'utf8')
`,
},
'pages/lab/slider/CustomIconSlider.js': {
Expand Down