Skip to content
This repository has been archived by the owner on Dec 23, 2022. It is now read-only.

Commit

Permalink
Fix floating label not working without hint text.
Browse files Browse the repository at this point in the history
Fixes #7.
  • Loading branch information
leMaik committed Sep 15, 2016
1 parent 39a8b69 commit 55a2ee3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/ChipInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,23 +290,23 @@ class ChipInput extends React.Component {

const inputStyleMerged = Object.assign(styles.input, inputStyle);

const showHintText = hintText && (this.props.value || this.state.chips).length === 0 && this.state.inputValue.length === 0
const hasInput = (this.props.value || this.state.chips).length > 0 || this.state.inputValue.length > 0
const showHintText = hintText && !hasInput
const shrinkFloatingLabel = floatingLabelText && (hasInput || this.state.isFocused)

const floatingLabelTextElement = floatingLabelText && (
<TextFieldLabel
muiTheme={this.context.muiTheme}
style={Object.assign(styles.floatingLabel, this.props.floatingLabelStyle)}
shrinkStyle={Object.assign(styles.floatingLabelFocusStyle, this.props.floatingLabelFocusStyle)}
htmlFor={inputId}
shrink={!showHintText || this.state.isFocused}
shrink={shrinkFloatingLabel}
disabled={disabled}
>
{floatingLabelText}
</TextFieldLabel>
)

const shrinkFloatingLabel = floatingLabelText && (!showHintText || this.state.isFocused)

const overrideRootStyles = {}
if (floatingLabelText) {
overrideRootStyles.marginTop = 14
Expand All @@ -320,7 +320,7 @@ class ChipInput extends React.Component {

return (
<div
style={prepareStyles(Object.assign({}, styles.root, style, overrideRootStyles))}
style={prepareStyles(Object.assign(styles.root, style, overrideRootStyles))}
onTouchTap={() => this.focus()}
>
<div>
Expand Down
15 changes: 10 additions & 5 deletions stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ storiesOf('ChipInput', module)
fullWidth
/>
))
.add('empty with hintText', () => themed(
.add('with hintText', () => themed(
<ChipInput
hintText="Insert your favorite tags here"
hintText="Hint text"
fullWidth
/>
))
Expand All @@ -45,9 +45,14 @@ storiesOf('ChipInput', module)
))
.add('with floating label', () => themed(
<ChipInput
defaultValue={['foo', 'bar']}
floatingLabelText="Some chips"
hintText="Try typing a..."
floatingLabelText="Floating label"
fullWidth
/>
))
.add('with floating label and hint text', () => themed(
<ChipInput
floatingLabelText="Floating label"
hintText="Hint text"
fullWidth
/>
))
Expand Down

0 comments on commit 55a2ee3

Please sign in to comment.