Fixes tab on Chip Input (#3022) (#3044)

This commit is contained in:
Nicolas Gotchac 2016-11-01 13:51:02 +01:00 committed by Jaco Greeff
parent 4d4b124efd
commit ff04c622f3
4 changed files with 51 additions and 15 deletions

View File

@ -107,7 +107,7 @@ export default class EditMeta extends Component {
onTokensChange={ this.onTagsChange } onTokensChange={ this.onTagsChange }
label='(optional) tags' label='(optional) tags'
hint='press <Enter> to add a tag' hint='press <Enter> to add a tag'
clearOnBlur addOnBlur
/> />
); );
} }

View File

@ -77,6 +77,8 @@ export default class ActionbarSearch extends Component {
onBlur={ this.handleSearchBlur } onBlur={ this.handleSearchBlur }
onInputChange={ this.handleInputChange } onInputChange={ this.handleInputChange }
onTokensChange={ this.handleTokensChange } onTokensChange={ this.handleTokensChange }
addOnBlur
/> />
</div> </div>

View File

@ -17,10 +17,10 @@
.chip { .chip {
& > svg { & > svg {
width: 1.2rem !important; width: 1rem !important;
height: 1.2rem !important; height: 1rem !important;
margin: initial !important; margin: initial !important;
margin-right: 4px !important; margin-right: 4px !important;
padding: 4px 0 !important; padding: 2px 0 !important;
} }
} }

View File

@ -31,17 +31,33 @@ export default class InputChip extends Component {
onTokensChange: PropTypes.func, onTokensChange: PropTypes.func,
onInputChange: PropTypes.func, onInputChange: PropTypes.func,
onBlur: PropTypes.func, onBlur: PropTypes.func,
addOnBlur: PropTypes.bool,
clearOnBlur: PropTypes.bool clearOnBlur: PropTypes.bool
} }
static defaultProps = { static defaultProps = {
clearOnBlur: false clearOnBlur: false,
addOnBlur: false
}
state = {
focused: false
} }
render () { render () {
const { clearOnBlur, className, hint, label, tokens } = this.props; const { clearOnBlur, className, hint, label, tokens } = this.props;
const { focused } = this.state;
const classes = `${className}`; const classes = `${className}`;
const textFieldStyle = {
height: 55
};
if (!focused) {
textFieldStyle.width = 0;
}
return ( return (
<ChipInput <ChipInput
className={ classes } className={ classes }
@ -54,6 +70,7 @@ export default class InputChip extends Component {
chipRenderer={ this.chipRenderer } chipRenderer={ this.chipRenderer }
onFocus={ this.handleFocus }
onBlur={ this.handleBlur } onBlur={ this.handleBlur }
onRequestAdd={ this.handleTokenAdd } onRequestAdd={ this.handleTokenAdd }
onRequestDelete={ this.handleTokenDelete } onRequestDelete={ this.handleTokenDelete }
@ -63,16 +80,19 @@ export default class InputChip extends Component {
fullWidth fullWidth
hintStyle={ { hintStyle={ {
bottom: 16, bottom: 13,
left: 1, left: 0,
transition: 'none' transition: 'none'
} } } }
inputStyle={ { inputStyle={ {
marginBottom: 18 marginBottom: 18,
width: 'initial'
} } } }
textFieldStyle={ { textFieldStyle={ textFieldStyle }
height: 42 underlineStyle={ {
} } /> borderWidth: 2
} }
/>
); );
} }
@ -84,7 +104,7 @@ export default class InputChip extends Component {
key={ key } key={ key }
className={ styles.chip } className={ styles.chip }
style={ { style={ {
margin: '8px 8px 0 0', margin: '15px 8px 0 0',
float: 'left', float: 'left',
pointerEvents: isDisabled ? 'none' : undefined, pointerEvents: isDisabled ? 'none' : undefined,
alignItems: 'center' alignItems: 'center'
@ -103,8 +123,19 @@ export default class InputChip extends Component {
); );
} }
handleFocus = () => {
this.setState({ focused: true });
}
handleBlur = () => { handleBlur = () => {
const { onBlur } = this.props; const { onBlur, addOnBlur } = this.props;
this.setState({ focused: false });
if (addOnBlur) {
const { inputValue } = this.refs.chipInput.state;
this.handleTokenAdd(inputValue);
}
if (typeof onBlur === 'function') { if (typeof onBlur === 'function') {
onBlur(); onBlur();
@ -118,8 +149,11 @@ export default class InputChip extends Component {
this.handleTokensChange(newTokens); this.handleTokensChange(newTokens);
if (value === this.refs.chipInput.state.inputValue && typeof onInputChange === 'function') { if (value === this.refs.chipInput.state.inputValue) {
onInputChange(''); if (typeof onInputChange === 'function') {
onInputChange('');
}
this.refs.chipInput.setState({ inputValue: '' });
} }
} }