Skip to content

Commit

Permalink
Use standard input for single-selection case (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericgio committed Jan 10, 2018
1 parent 9ae5656 commit 801fd63
Showing 1 changed file with 52 additions and 14 deletions.
66 changes: 52 additions & 14 deletions src/HintedInput.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,46 @@ const STYLES = {
padding: 0,
};

// Shim around a standard input to normalize how props are applied.
class StandardInput extends React.Component {
render() {
const {inputClassName, inputStyle, ...otherProps} = this.props;

return (
<input
{...otherProps}
className={inputClassName}
ref={(input) => this._input = input}
style={{
...STYLES,
...inputStyle,
width: '100%',
}}
/>
);
}

// Mirror the AutosizeInput API for consistency.
getInput = () => {
return this._input;
}
}

class HintedInput extends React.Component {
render() {
return (
<div
style={{
display: this.props.multiple ? 'inline-block' : 'block',
position: 'relative',
}}>
{this._renderInput()}
{this._renderHint()}
</div>
);
}

_renderInput = () => {
const {
className,
hintText,
Expand All @@ -23,21 +61,21 @@ class HintedInput extends React.Component {
...props
} = this.props;

// Render a standard input in the single-select case to address #278.
const InputComponent = multiple ? AutosizeInput : StandardInput;

return (
<div style={{display: 'inline-block', position: 'relative'}}>
<AutosizeInput
{...props}
autoComplete="off"
inputClassName={cx('rbt-input-main', className)}
inputStyle={STYLES}
ref={inputRef}
style={{
position: 'relative',
zIndex: 1,
}}
/>
{this._renderHint()}
</div>
<InputComponent
{...props}
autoComplete="off"
inputClassName={cx('rbt-input-main', className)}
inputStyle={STYLES}
ref={inputRef}
style={{
position: 'relative',
zIndex: 1,
}}
/>
);
}

Expand Down

0 comments on commit 801fd63

Please sign in to comment.