Skip to content

Commit

Permalink
Merge pull request #3646 from Dashlane/feature/text-field-floating-la…
Browse files Browse the repository at this point in the history
…bel-shrink

[TextField] Add floatingLabelFixed property
  • Loading branch information
nathanmarks committed Mar 10, 2016
2 parents f586c23 + edb8ad9 commit 04e81b1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ const TextFieldExampleSimple = () => (
hintText="Hint Text"
floatingLabelText="Floating Label Text"
/><br />
<TextField
hintText="Hint Text"
floatingLabelText="Fixed Floating Label Text"
floatingLabelFixed={true}
/><br />
<TextField
hintText="Password Field"
floatingLabelText="Password"
Expand Down
11 changes: 9 additions & 2 deletions src/TextField/TextField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ const TextField = React.createClass({
*/
errorText: React.PropTypes.node,

/**
* If true, the floating label will float even when there is no value.
*/
floatingLabelFixed: React.PropTypes.bool,

/**
* The style object to use to override floating label styles.
*/
Expand Down Expand Up @@ -404,6 +409,7 @@ const TextField = React.createClass({
disabled,
errorStyle,
errorText,
floatingLabelFixed,
floatingLabelText,
fullWidth,
hintText,
Expand Down Expand Up @@ -443,7 +449,7 @@ const TextField = React.createClass({
muiTheme={this.state.muiTheme}
style={Object.assign(styles.floatingLabel, this.props.floatingLabelStyle)}
htmlFor={inputId}
shrink={this.state.hasValue || this.state.isFocused}
shrink={this.state.hasValue || this.state.isFocused || floatingLabelFixed}
disabled={disabled}
>
{floatingLabelText}
Expand Down Expand Up @@ -501,7 +507,8 @@ const TextField = React.createClass({
{hintText ?
<TextFieldHint
muiTheme={this.state.muiTheme}
show={!(this.state.hasValue || (floatingLabelText && !this.state.isFocused))}
show={!(this.state.hasValue || (floatingLabelText && !this.state.isFocused)) ||
(!this.state.hasValue && floatingLabelText && floatingLabelFixed && !this.state.isFocused)}
style={hintStyle}
text={hintText}
/> :
Expand Down

0 comments on commit 04e81b1

Please sign in to comment.