-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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] Port component #10665
[Slider] Port component #10665
Conversation
@epodivilov Looks like a great start! We are putting newly created / migrated components in |
@mbrookes Thanks. Will be done! Maybe worth adding information about packages/material-ui-lab to the file CONTRIBUTING.md? |
@epodivilov Good point. Done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please could you move the demos under docs/src/pages/lab
?
@mbrookes Ok. Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, was too hasty in my last review.
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { withStyles } from 'material-ui/styles'; | ||
import Slider from '../../../../../packages/material-ui-lab/src/Slider/Slider'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use import Slider from '@material-ui/lab/Slider'
across the demos.
docs/src/pages/lab/slider/slider.md
Outdated
A [slider](https://material.io/guidelines/components/sliders.html) is an interface for users to input a value in a range. Sliders can be continuous or discrete and can be enabled or disabled. | ||
|
||
## Simple slider | ||
{{"demo": "pages/demos/slider/SimpleSlider.js"}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
paths need to be updated
pages/lab/slider.js
Outdated
<MarkdownDocs | ||
markdown={markdown} | ||
demos={{ | ||
'pages/demos/slider/SimpleSlider.js': { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
paths need to be updated
@mbrookes Ok, I updated paths |
import withStyles from '../../../../src/styles/withStyles'; | ||
import ButtonBase from '../../../../src/ButtonBase'; | ||
import addEventListener from '../../../../src/utils/addEventListener'; | ||
import { fade } from '../../../../src/styles/colorManipulator'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should import from material-ui
.
@mbrookes And I can't understand, why happend "Deploy preview failed." Could you explain the order of adding a new component? Given the location of this component in the lab? |
@epodivilov I was thinking more of the ARIA attributes (Roles, States, and Properties) - as much as possible this should be handled by the component, however it looks like we should also support home / end key at least. (Page up / down is optional). |
Not sure, we're just experimenting with Netlify. You could try rebasing off v1-beta.
Sorry, not sure I understand the question? |
Ok, I will add support home / end keys. And about my previous question. For example:
Right now I`m not shure, that all my changes is needed. For example changes in modules/components/withRoot.js |
Thanks for adding those. 👍 It would be ideal if you could also label the sliders in the examples, and show the correct usage of |
@epodivilov Yes, you're right, the contributing guide hasn't kept up with changes to the project. I'll take a look. The main omission is think is the |
Just noticed that the description for min and max aren't correct. (I realised they were copied from v0, and see that they aren't correct there either!). You could drop the words " on a scale from 0 to 1 inclusive". Also, perhaps "Cannot be equal to min." should be "Should not be equal to min."? (It can, but it shouldn't...) |
@epodivilov Thanks for following up so quickly on the changes - at this rate it's going to be ready for v1 rather than lab! 😄 I'm snowed with work at the mo, but I promise to give it a proper review next week. @ me if I haven't checked in. |
Hello @mbrookes! (I know, it's thursday, I'm not the person who authored this PR, etc etc. I'm just a poor frontend developer with a deadline coming up who would rather use a material-ui solution than adding and customizing rc-slider to spec. 🤷♂️ ) |
I hadn't forgotten, I promise. 😇 @Aubron If you wanted to help in the meantime, you can take a look at it here and test it out. @epodivilov A couple of issues I was going to dig into that you could take a look at:
|
Thanks for working on this component @epodivilov! I copy pasted this into a project some days ago because it was the last missing 1.0 component :). I noticed one issue as well:
I added a |
@mbrookes I made some changes. But I`m not understood issue about focus. It is standard behavior of element. Look at the example with the standard HTML component https://codepen.io/anon/pen/jzQEJP @goto-bus-stop Thanks for the feedback 👍 With your help I found a couple of bugs and fixed them. |
Some things I noticed by trying https://deploy-preview-10665--material-ui-next.netlify.com/lab/slider/
Thank you for working on this! |
import { withStyles } from 'material-ui/styles'; | ||
import Slider from '@material-ui/lab/Slider'; | ||
|
||
const styles = () => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the function.
<div className={classes.container}> | ||
<Slider value={0} min={0} max={6} disabled /> | ||
<Slider value={3} min={0} max={6} disabled /> | ||
<Slider value={6} min={0} max={6} disabled /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to include props that match the defaults (min).
global.addEventListener('touchstart', this.touchStart, { passive: false }); | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update this for React 16.3? We're using the polyfill for the new lifecycle methods to support earlier versions.
END: 35, | ||
}; | ||
|
||
function normalizeValue(value, min = 0, max = 100) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We call this 'clamp' in other parts of the code (CircularProgress, and colorManipulator, where it also gives a warning of out-of-range). I wonder if it should move to utils as a shared function?
}; | ||
} | ||
|
||
function normalizeValue(value, min = 0, max = 100) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We call this clamp
elsewhere (CircularProgress and colorManipulator, where it also gives a warning for out-of-range values). I wonder if we should move it to utils as a shared function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the implementation of this vs CircularProgress, that seems reasonable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where I should place function? In /src/utils or in /packages/material-ui-lab/src/utils ?
When you tab focus the Slider with the keyboard, it gets a focus indicator: (Ideally that would be the pulsating focusRipple, rather than static, but lets come back to that). In Chrome, when you click the Thumb, then "on mouse up" the keyboard focus is being applied - the focus indicator appears, even though there was no keyboard interaction. |
Ouch! I didn't even spot this until I disabled the transition. For the continuous slider, MCW is using 1% for up / down, and 4% for page-up / page-down for keyboard input, while mouse granularity is effectively determined by the screen resolution. Those seem like sensible defaults. v0.x is also using 1% for up/down, but doesn't support page up / down.
Out of idle curiosity, I replaced the track with a restyled |
One more thing: The slider should continue to slide even when the mouse is outside the container. |
secondary: '#bdbdbd', | ||
focused: '#9e9e9e', | ||
disabled: '#bdbdbd', | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These colours need to be taken from the theme so users can modify them - either directly from theme.palette.grey
, or colorManipulator
'd version of them.
@epodivilov Thanks for persevering with it! See you on #11040 👍 |
Added implementation of the Slider component according to the Google guidelines
Closes #4793