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 floating when there are chips but no input or …
Browse files Browse the repository at this point in the history
…focus.

Fixes #259
  • Loading branch information
leMaik committed Jan 23, 2019
1 parent af240a4 commit 4d32791
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
4 changes: 3 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions src/ChipInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ class ChipInput extends React.Component {
const hasInput = (this.props.value || actualInputValue).length > 0 || actualInputValue.length > 0
const shrinkFloatingLabel = InputLabelProps.shrink != null
? InputLabelProps.shrink
: (label != null && (hasInput || this.state.isFocused))
: (label != null && (hasInput || this.state.isFocused || chips.length > 0))

const chipComponents = chips.map((tag, i) => {
const value = dataSourceConfig ? tag[dataSourceConfig.value] : tag
Expand All @@ -490,10 +490,7 @@ class ChipInput extends React.Component {

const InputMore = {}
if (variant === 'outlined') {
if (InputLabelProps && typeof InputLabelProps.shrink !== 'undefined') {
InputMore.notched = InputLabelProps.shrink
}

InputMore.notched = shrinkFloatingLabel
InputMore.labelWidth =
(shrinkFloatingLabel && this.labelNode && this.labelNode.offsetWidth) ||
0
Expand Down
2 changes: 1 addition & 1 deletion src/ChipInput.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ describe('floating label', () => {

it('shrinks if there are chips', () => {
const tree = mount(
<ChipInput label='Floating label' value={['foo']} />
<ChipInput label='Floating label' defaultValue={['asdf']} />
)
expect(tree.find('InputLabel').prop('shrink')).toBe(true)
})
Expand Down

0 comments on commit 4d32791

Please sign in to comment.