Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Customize input element of combobox #145

Merged
merged 3 commits into from
Jan 3, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/Select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -507,15 +507,19 @@ const Select = React.createClass({

getInputElement() {
const props = this.props;
const inputElement = props.getInputElement ? props.getInputElement() : <input />;
const inputCls = classnames(inputElement.props.className, {
[`${props.prefixCls}-search__field`]: true,
});
return (<div className={`${props.prefixCls}-search__field__wrap`}>
<input
ref={this.saveInputRef}
onChange={this.onInputChange}
onKeyDown={this.onInputKeyDown}
value={this.state.inputValue}
disabled={props.disabled}
className={`${props.prefixCls}-search__field`}
/>
{React.cloneElement(inputElement, {
ref: this.saveInputRef,
onChange: this.onInputChange,
onKeyDown: this.onInputKeyDown,
value: this.state.inputValue,
disabled: props.disabled,
className: inputCls,
})}
<span
ref={this.saveInputMirrorRef}
className={`${props.prefixCls}-search__field__mirror`}
Expand Down
16 changes: 16 additions & 0 deletions tests/Select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,4 +408,20 @@ describe('Select', () => {

expect(input.focus).toBeCalled();
});

it('combox could comstomize input element', () => {
const wrapper = mount(
<Select combobox getInputElement={() => <textarea />}>
<Option value="1">1</Option>
<Option value="2">2</Option>
</Select>
);

expect(wrapper.find('textarea').length).toBe(1);
wrapper.find('.rc-select').simulate('click');
const dropdownWrapper = mount(wrapper.find('Trigger').node.getComponent());

dropdownWrapper.find('MenuItem').first().simulate('click');
expect(wrapper.state().inputValue).toBe('1');
});
});