Skip to content

Commit

Permalink
[Input] Better placeholder display logic (#8485)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Sep 30, 2017
1 parent 144907f commit cfb2edb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
5 changes: 4 additions & 1 deletion docs/src/pages/demos/text-fields/TextFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ class TextFields extends React.Component {
<TextField
id="full-width"
label="Label"
InputProps={{ placeholder: 'Placeholder' }}
InputLabelProps={{
shrink: true,
}}
placeholder="Placeholder"
helperText="Full width!"
fullWidth
margin="normal"
Expand Down
26 changes: 13 additions & 13 deletions src/Input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ export const styles = (theme: Object) => {
const placeholder = {
color: 'currentColor',
opacity: theme.palette.type === 'light' ? 0.42 : 0.5,
};
const placeholderForm = {
opacity: 0,
transition: theme.transitions.create('opacity', {
duration: theme.transitions.duration.shorter,
easing: theme.transitions.easing.ease,
}),
};
const placeholderFormFocus = {
const placeholderHidden = {
opacity: 0,
};
const placeholderVisible = {
opacity: theme.palette.type === 'light' ? 0.42 : 0.5,
};

Expand Down Expand Up @@ -118,15 +118,15 @@ export const styles = (theme: Object) => {
appearance: 'none',
},
// Show and hide the placeholder logic
'label + $formControl &': {
'&::-webkit-input-placeholder': placeholderForm,
'&::-moz-placeholder': placeholderForm, // Firefox 19+
'&:-ms-input-placeholder': placeholderForm, // IE 11
'&::-ms-input-placeholder': placeholderForm, // Edge
'&:focus::-webkit-input-placeholder': placeholderFormFocus,
'&:focus::-moz-placeholder': placeholderFormFocus, // Firefox 19+
'&:focus:-ms-input-placeholder': placeholderFormFocus, // IE 11
'&:focus::-ms-input-placeholder': placeholderFormFocus, // Edge
'label[data-shrink=false] + $formControl &': {
'&::-webkit-input-placeholder': placeholderHidden,
'&::-moz-placeholder': placeholderHidden, // Firefox 19+
'&:-ms-input-placeholder': placeholderHidden, // IE 11
'&::-ms-input-placeholder': placeholderHidden, // Edge
'&:focus::-webkit-input-placeholder': placeholderVisible,
'&:focus::-moz-placeholder': placeholderVisible, // Firefox 19+
'&:focus:-ms-input-placeholder': placeholderVisible, // IE 11
'&:focus::-ms-input-placeholder': placeholderVisible, // Edge
},
},
inputDense: {
Expand Down
2 changes: 1 addition & 1 deletion src/Input/InputLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function InputLabel(props: ProvidedProps & Props, context: { muiFormControl: Obj
);

return (
<FormLabel className={className} classes={FormControlClasses} {...other}>
<FormLabel data-shrink={shrink} className={className} classes={FormControlClasses} {...other}>
{children}
</FormLabel>
);
Expand Down

0 comments on commit cfb2edb

Please sign in to comment.