-
-
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
[TextField] Make it meet guidelines #6566
[TextField] Make it meet guidelines #6566
Conversation
src/Form/FormControl.js
Outdated
const dirty = props.children.some((child) => { | ||
return child.type && child.type.name === 'Input' && | ||
child.props.value && child.props.value.length > 0; | ||
}); |
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.
This looks complex. Any better way?
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.
Good question! I can't think of a better alternative 🤔 .
Notice that there is an ongoing effort for the multiline implementation #6553. |
@oliviertassinari that's great. Will take it into account. |
src/Form/FormControl.js
Outdated
constructor(props, context) { | ||
super(props, context); | ||
|
||
const dirty = props.children.some((child) => { |
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.
Nothing guarantee the props.children
to be a flat array.
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.
React provides a Children.map
utility function.
src/Form/FormControl.js
Outdated
|
||
const dirty = props.children.some((child) => { | ||
return child.type && child.type.name === 'Input' && | ||
child.props.value && child.props.value.length > 0; |
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.
What about importing the isDirty
function from the Input.js
? I think that's safer that way.
src/Form/FormControl.js
Outdated
const dirty = props.children.some((child) => { | ||
return child.type && child.type.name === 'Input' && | ||
child.props.value && child.props.value.length > 0; | ||
}); |
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.
Good question! I can't think of a better alternative 🤔 .
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.
Looks like it's going in the right direction 😄 .
src/Form/FormControl.js
Outdated
@@ -78,6 +79,18 @@ export default class FormControl extends Component { | |||
}; | |||
} | |||
|
|||
componentWillMount() { | |||
let dirty = false; | |||
Children.map(this.props.children, (child) => { |
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.
What about a forEach
?
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.
Yes this should work in this case)
src/Form/FormHelperText.js
Outdated
root: { | ||
color: theme.palette.input.helperText, | ||
fontSize: 12, | ||
lineHeight: 1.33333333, |
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.
I don't think that we need as many significant number.
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.
@oliviertassinari In Chrome 1.3333333 lineheight = 16px height, 1.333333 = 14 px 😄 I set it 1.4 also gives 16px but don't know how in can affect browsers when using retina display.
src/TextField/TextFieldLabel.js
Outdated
import customPropTypes from '../utils/customPropTypes'; | ||
import { FormLabel } from '../Form'; | ||
|
||
export const styleSheet = createStyleSheet('MuiTextFieldLabel', (theme) => { |
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.
Oops, a dead component 🙈 , good catch!
…text-field-guidelines
src/Form/FormHelperText.js
Outdated
@@ -12,7 +12,7 @@ export const styleSheet = createStyleSheet('MuiFormHelperText', (theme) => { | |||
root: { | |||
color: theme.palette.input.helperText, | |||
fontSize: 12, | |||
lineHeight: 1.33333333, | |||
lineHeight: 1.4, |
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.
Wouldn't 1.3' round to 1.3?
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.
1.3 results to 15px line-height in webkit...
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.
Gotcha.
@kybarg The I have one concern with the new height of the TextField. |
src/Input/InputLabel.js
Outdated
}, | ||
shrink: { | ||
transform: 'translate(0, 0px) scale(0.75)', | ||
transform: `translate(0, ${theme.spacing.unit * 2 + 2.5}px) scale(0.75)`, |
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.
I would avoid any 1/x px computation as unpredictable and subject to GPU floating error.
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.
But why not keeping it for now.
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.
Without this hack, other inputs labels flicker when focusing one. Couldn't find better solution.
Only if we switch from transitions to animation.
@oliviertassinari I wouldn't stick with Polymer's implementation. Found many differences between it and official guidelines. |
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.
material-web-components and polymer are two excellent reference implementation. Pick one and we will be happy 😄 .
easing: theme.transitions.easing.ease, | ||
}), | ||
}, | ||
'&:focus::-webkit-input-placeholder': { |
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.
Can't we use a single selector instead of repeating the opacity:
property?
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.
@oliviertassinari JSS
currently doesn't support prefixing ::placeholder
selector. But there is discussion on this issue. Hope the will release it soon.
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.
I was suggesting doing the following, but I'm not 100% sure it's working.
'&:focus::-moz-placeholder, &:focus:-ms-input-placeholder, &:focus::-moz-placeholder, &:focus::-webkit-input-placeholder': {
opacity: theme.palette.type === 'light' ? 0.42 : 0.5,
},
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.
@oliviertassinari unfortunately not 😢
…text-field-guidelines # Conflicts: # src/styles/MuiThemeProvider.js
@oliviertassinari I've made this based on sticker sheet and specs |
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.
@kybarg So nearly there - just some tiny changes to standardize the prop labels, but before you follow my comments, when I got to the bottom there was this one:
@oliviertassinari Any preference?
src/Form/FormControl.js
Outdated
@@ -115,6 +127,10 @@ FormControl.propTypes = { | |||
*/ | |||
className: PropTypes.string, | |||
/** | |||
* If `true`, the label should be displayed in an disabled state. | |||
*/ |
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.
'a disabled state'
src/Form/FormHelperText.js
Outdated
disabled: PropTypes.bool, | ||
/** | ||
* Whether the helper text should be displayed in an error state. | ||
*/ |
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.
'If true
,'
src/Form/FormHelperText.js
Outdated
*/ | ||
className: PropTypes.string, | ||
/** | ||
* Whether the helper text should be displayed in an disabled state. |
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.
'If true
,' ... 'a disabled state.'
src/Form/FormHelperText.spec.js
Outdated
}); | ||
|
||
describe('prop: error', () => { | ||
it('should show an error class', () => { |
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.
'should have an error class' / 'should set the error class'?
src/Form/FormLabel.js
Outdated
@@ -91,6 +100,10 @@ FormLabel.propTypes = { | |||
*/ | |||
className: PropTypes.string, | |||
/** | |||
* Whether the label should be displayed in an disabled state. |
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.
'If true,' ... 'a disabled state.'
src/Form/FormLabel.js
Outdated
* Whether the label should be displayed in an disabled state. | ||
*/ | ||
disabled: PropTypes.bool, | ||
/** | ||
* Whether the label should be displayed in an error state. |
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.
'If true,'
@@ -81,6 +86,10 @@ InputLabel.propTypes = { | |||
*/ | |||
disableAnimation: PropTypes.bool, | |||
/** | |||
* If `true`, apply disabled class. |
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.
'If true
, apply the disabled
CSS class'.
Hmmm, now I wonder if all the others should follow that pattern. It's clearer to the user what the outcome of applying this prop is when it comes to custom styling.
@kybarg You rock, let's merge this 🚀 ! |
Hello After this merge, the height of a TextField is much bigger than previously, with a big margin on top. I didn't find a way to make it more compact. Is there one ? Thank you for your work :) |
@micaste Hi! Default input has height of |
@kybarg I'm wondering if we shouldn't reduce the height of the TextField and expose an optional property to enable some margin, the margins suggested by the documentation. |
@oliviertassinari I see spec as priority as it tries to cover most common cases. I believe non standard implementation is not very common 💭 Also I want to add "dense" variant. Maybe this can help in some cases as well 😄 |
@kybarg any style override to suggest ? I tried but I can only break the thing apparently. |
Multiline text support closes [TextField] Multiline text support #6288[TextField] Add in support for multiline text fields #6553TextFieldLabel
component closes [TextFieldLabel] Is there need for this component #6580Update "Supported components" docs page