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

Fix error on click placeholder #80

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions examples/single-without-search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
placeholder
97 changes: 97 additions & 0 deletions examples/single-without-search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* eslint no-console: 0 */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个例子删掉,不需要,现有例子有


import React from 'react';
import Select, { Option } from 'rc-select';
import 'rc-select/assets/index.less';
import ReactDOM from 'react-dom';

const Test = React.createClass({
getInitialState() {
return {
destroy: false,
value: String(9),
};
},

onChange(e) {
let value;
if (e && e.target) {
value = e.target.value;
} else {
value = e;
}
this.setState({
value,
});
},

onDestroy() {
this.setState({
destroy: 1,
});
},

render() {
if (this.state.destroy) {
return null;
}
return (
<div style={{ margin: 20 }}>
<div style={{ height: 150 }}/>

<h2>Single Select without search</h2>

<div style={{ width: 300 }}>
<Select
value={this.state.value}
placeholder="placeholder"
dropdownMenuStyle={{ maxHeight: 200, overflow: 'auto' }}
style={{ width: 500 }}
allowClear
showSearch={false}
optionLabelProp="children"
optionFilterProp="text"
onChange={this.onChange}
>
<Option value="01" text="jack">
<b
style={{
color: 'red',
}}
>
jack
</b>
</Option>
<Option value="11" text="lucy">lucy</Option>
<Option value="21" disabled text="disabled">disabled</Option>
<Option value="31" text="yiminghe">yiminghe</Option>
{[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map((i) => {
return <Option key={i} text={String(i)}>{i}</Option>;
})}
</Select>
</div>

<h2>native select</h2>
<select
value={this.state.value}
style={{ width: 500 }}
onChange={this.onChange}
>
<option value="01">jack</option>
<option value="11">lucy</option>
<option value="21" disabled>disabled</option>
<option value="31">yiminghe</option>
{[1, 2, 3, 4, 5, 6, 7, 8, 9].map((i) => {
return <option value={i} key={i}>{i}</option>;
})}
</select>

<p>
<button onClick={this.onDestroy}>destroy</button>
</p>
</div>
);
},
});

ReactDOM.render(<Test />, document.getElementById('__react-content'));
4 changes: 3 additions & 1 deletion src/Select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ const Select = React.createClass({
},

onPlaceholderClick() {
this.getInputDOMNode().focus();
if (this.props.showSearch) {
this.getInputDOMNode().focus();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if(this.getInputDOMNode()){
this.getInputDOMNode().focus();
}

}
},

onOuterFocus() {
Expand Down