Skip to content

Commit fd1cef7

Browse files
committed
Merge pull request mui#1468 from KapJI/slider-appearance
[Slider] fix handle focus appearance
2 parents 0968696 + 3560885 commit fd1cef7

File tree

2 files changed

+43
-54
lines changed

2 files changed

+43
-54
lines changed

src/slider.jsx

Lines changed: 42 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,9 @@ let Slider = React.createClass({
106106
},
107107

108108
getStyles() {
109-
let size = this.getTheme().handleSize + this.getTheme().trackSize;
110-
let gutter =
111-
(this.getTheme().handleSizeDisabled + this.getTheme().trackSize) / 2;
112-
let fillGutter =
113-
this.getTheme().handleSizeDisabled - this.getTheme().trackSize;
109+
let fillGutter = this.getTheme().handleSize / 2;
110+
let disabledGutter = this.getTheme().trackSize + this.getTheme().handleSizeDisabled / 2;
111+
let calcDisabledSpacing = this.props.disabled ? ' - ' + disabledGutter + 'px' : '';
114112
let styles = {
115113
root: {
116114
touchCallout: 'none',
@@ -134,10 +132,6 @@ let Slider = React.createClass({
134132
height: '100%',
135133
transition: Transitions.easeOut(null, 'margin'),
136134
},
137-
percentZeroRemaining: {
138-
left: 1,
139-
marginLeft: gutter,
140-
},
141135
handle: {
142136
boxSizing: 'border-box',
143137
position: 'absolute',
@@ -155,7 +149,8 @@ let Slider = React.createClass({
155149
borderRadius: '50%',
156150
transform: 'translate(-50%, -50%)',
157151
transition:
158-
Transitions.easeOut('450ms', 'border') + ',' +
152+
Transitions.easeOut('450ms', 'background') + ',' +
153+
Transitions.easeOut('450ms', 'border-color') + ',' +
159154
Transitions.easeOut('450ms', 'width') + ',' +
160155
Transitions.easeOut('450ms', 'height'),
161156
overflow: 'visible',
@@ -166,37 +161,40 @@ let Slider = React.createClass({
166161
backgroundColor: this.getTheme().trackColor,
167162
width: this.getTheme().handleSizeDisabled,
168163
height: this.getTheme().handleSizeDisabled,
169-
border: '2px solid white',
164+
border: 'none',
170165
},
171166
handleWhenPercentZero: {
172-
border: this.getTheme().trackSize + 'px solid ' + this.getTheme().trackColor,
167+
border: this.getTheme().trackSize + 'px solid ' + this.getTheme().handleColorZero,
173168
backgroundColor: this.getTheme().handleFillColor,
174169
boxShadow: 'none',
175170
},
171+
handleWhenPercentZeroAndDisabled: {
172+
cursor: 'not-allowed',
173+
width: this.getTheme().handleSizeDisabled,
174+
height: this.getTheme().handleSizeDisabled,
175+
},
176+
handleWhenPercentZeroAndFocused: {
177+
border: this.getTheme().trackSize + 'px solid ' +
178+
this.getTheme().trackColorSelected,
179+
},
176180
handleWhenActive: {
177-
borderColor: this.getTheme().trackColorSelected,
178181
width: this.getTheme().handleSizeActive,
179182
height: this.getTheme().handleSizeActive,
180-
transition:
181-
Transitions.easeOut('450ms', 'backgroundColor') + ',' +
182-
Transitions.easeOut('450ms', 'width') + ',' +
183-
Transitions.easeOut('450ms', 'height'),
184183
},
185-
ripples: {
186-
height: '300%',
187-
width: '300%',
188-
top: '-12px',
189-
left: '-12px',
184+
ripple: {
185+
height: this.getTheme().handleSize,
186+
width: this.getTheme().handleSize,
187+
overflow: 'visible',
190188
},
191-
handleWhenDisabledAndZero: {
192-
width: (size / 2) + 'px',
193-
height: (size /2) + 'px',
189+
rippleWhenPercentZero: {
190+
top: -this.getTheme().trackSize,
191+
left: -this.getTheme().trackSize,
194192
},
195-
handleWhenPercentZeroAndHovered: {
196-
border: this.getTheme().trackSize + 'px solid ' +
197-
this.getTheme().handleColorZero,
198-
width: size + 'px',
199-
height: size + 'px',
193+
rippleInner: {
194+
height: '300%',
195+
width: '300%',
196+
top: -this.getTheme().handleSize,
197+
left: -this.getTheme().handleSize,
200198
},
201199
};
202200
styles.filled = this.mergeAndPrefix(styles.filledAndRemaining, {
@@ -205,13 +203,13 @@ let Slider = React.createClass({
205203
this.getTheme().trackColor :
206204
this.getTheme().selectionColor,
207205
marginRight: fillGutter,
208-
width: (this.state.percent * 100) + (this.props.disabled ? -1 : 0) + '%',
206+
width: 'calc(' + (this.state.percent * 100) + '%' + calcDisabledSpacing + ')',
209207
});
210208
styles.remaining = this.mergeAndPrefix(styles.filledAndRemaining, {
211209
right: 0,
212210
backgroundColor: this.getTheme().trackColor,
213211
marginLeft: fillGutter,
214-
width: ((1 - this.state.percent) * 100) + (this.props.disabled ? -1 : 0) + '%',
212+
width: 'calc(' + ((1 - this.state.percent) * 100) + '%' + calcDisabledSpacing + ')',
215213
});
216214

217215
return styles;
@@ -221,41 +219,33 @@ let Slider = React.createClass({
221219
let { ...others } = this.props;
222220
let percent = this.state.percent;
223221
if (percent > 1) percent = 1; else if (percent < 0) percent = 0;
224-
let gutter = (this.getTheme().handleSizeDisabled + this.getTheme().trackSize) / 2;
225-
let fillGutter = this.getTheme().handleSizeDisabled - this.getTheme().trackSize;
226222

227223
let styles = this.getStyles();
228224
let sliderStyles = this.mergeAndPrefix(styles.root, this.props.style);
229-
let trackStyles = styles.track;
230-
let filledStyles = styles.filled;
231-
let remainingStyles = this.mergeAndPrefix(
232-
styles.remaining,
233-
percent === 0 && styles.percentZeroRemaining
234-
);
235225
let handleStyles = percent === 0 ? this.mergeAndPrefix(
236226
styles.handle,
237227
styles.handleWhenPercentZero,
238228
this.state.active && styles.handleWhenActive,
239229
this.state.focused && {outline: 'none'},
240-
this.state.hovered && styles.handleWhenPercentZeroAndHovered,
241-
this.props.disabled && styles.handleWhenDisabledAndZero
230+
(this.state.hovered || this.state.focused) && !this.props.disabled
231+
&& styles.handleWhenPercentZeroAndFocused,
232+
this.props.disabled && styles.handleWhenPercentZeroAndDisabled,
242233
) : this.mergeAndPrefix(
243234
styles.handle,
244235
this.state.active && styles.handleWhenActive,
245236
this.state.focused && {outline: 'none'},
246237
this.props.disabled && styles.handleWhenDisabled
247238
);
248-
249-
let rippleStyle = {height: '12px', width: '12px', overflow: 'visible'};
250-
239+
let rippleStyle = this.mergeAndPrefix(
240+
styles.ripple,
241+
percent === 0 && styles.rippleWhenPercentZero,
242+
);
243+
let remainingStyles = styles.remaining;
251244
if ((this.state.hovered || this.state.focused) && !this.props.disabled) {
252245
remainingStyles.backgroundColor = this.getTheme().trackColorSelected;
253246
}
254247

255-
if (percent === 0) filledStyles.marginRight = gutter;
256-
if (this.state.percent === 0 && this.state.active) remainingStyles.marginLeft = fillGutter;
257-
258-
let rippleShowCondition = (this.state.hovered || this.state.focused) && !this.state.active && this.state.percent !== 0;
248+
let rippleShowCondition = (this.state.hovered || this.state.focused) && !this.state.active;
259249
let rippleColor = this.state.percent === 0 ? this.getTheme().handleColorZero : this.getTheme().rippleColor;
260250
let focusRipple;
261251
if (!this.props.disabled && !this.props.disableFocusRipple) {
@@ -264,12 +254,11 @@ let Slider = React.createClass({
264254
ref="focusRipple"
265255
key="focusRipple"
266256
style={rippleStyle}
267-
innerStyle={styles.ripples}
257+
innerStyle={styles.rippleInner}
268258
show={rippleShowCondition}
269259
color={rippleColor}/>
270260
);
271261
}
272-
273262
return (
274263
<div {...others } style={this.props.style}>
275264
<span className="mui-input-highlight"></span>
@@ -283,8 +272,8 @@ let Slider = React.createClass({
283272
onMouseEnter={this._onMouseEnter}
284273
onMouseLeave={this._onMouseLeave}
285274
onMouseUp={this._onMouseUp} >
286-
<div ref="track" style={trackStyles}>
287-
<div style={filledStyles}></div>
275+
<div ref="track" style={styles.track}>
276+
<div style={styles.filled}></div>
288277
<div style={remainingStyles}></div>
289278
<Draggable axis="x" bound="point"
290279
cancel={this.props.disabled ? '*' : null}

src/styles/themes/light-theme.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ let LightTheme = {
131131
trackColorSelected: Colors.grey500,
132132
handleSize: 12,
133133
handleSizeDisabled: 8,
134+
handleSizeActive: 18,
134135
handleColorZero: Colors.grey400,
135136
handleFillColor: Colors.white,
136137
selectionColor: palette.primary3Color,
@@ -215,7 +216,6 @@ let LightTheme = {
215216
obj.floatingActionButton.disabledTextColor = ColorManipulator.fade(palette.textColor, 0.3);
216217
obj.raisedButton.disabledColor = ColorManipulator.darken(obj.raisedButton.color, 0.1);
217218
obj.raisedButton.disabledTextColor = ColorManipulator.fade(obj.raisedButton.textColor, 0.3);
218-
obj.slider.handleSizeActive = obj.slider.handleSize * 2;
219219
obj.toggle.trackRequiredColor = ColorManipulator.fade(obj.toggle.thumbRequiredColor, 0.5);
220220

221221
return obj;

0 commit comments

Comments
 (0)