Skip to content

Commit

Permalink
Merge pull request #290 from react-component/yu-fixfilter
Browse files Browse the repository at this point in the history
fix: value is wrong when blur, close ant-design/ant-design#10134
  • Loading branch information
afc163 authored Apr 19, 2018
2 parents e863267 + 489be49 commit 976bc96
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
5 changes: 2 additions & 3 deletions examples/single.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ReactDOM from 'react-dom';
class Test extends React.Component {
state = {
destroy: false,
value: String(9),
value: 9,
};

onChange = (e) => {
Expand Down Expand Up @@ -76,11 +76,10 @@ class Test extends React.Component {
<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>;
return <Option key={i} value={i} text={String(i)}>{i}-text</Option>;
})}
</Select>
</div>

<h2>native select</h2>
<select
value={this.state.value}
Expand Down
2 changes: 1 addition & 1 deletion src/Select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ export default class Select extends React.Component {
if (options.length) {
const firstOption = findFirstMenuItem(options);
if (firstOption) {
value = [firstOption.key];
value = [getValuePropValue(firstOption)];
this.fireChange(value);
}
}
Expand Down
11 changes: 8 additions & 3 deletions tests/Select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,10 @@ describe('Select', () => {
onChange={handleChange}
onBlur={handleBlur}
showSearch
optionLabelProp="children"
>
<Option value="1">1</Option>
<Option value="2">2</Option>
<Option value={1} key={1}>1-text</Option>
<Option value={2} key={2}>2-text</Option>
</Select>
);
jest.useFakeTimers();
Expand All @@ -447,12 +448,16 @@ describe('Select', () => {
jest.runAllTimers();
});

it('will be auto select', () => {
expect(wrapper.update().find('.rc-select-selection-selected-value').text()).toBe('1-text');
});

it('set _focused to false', () => {
expect(wrapper.instance()._focused).toBe(false);
});

it('fires change event', () => {
expect(handleChange).toBeCalledWith('1', expect.anything());
expect(handleChange).toBeCalledWith(1, expect.anything());
});

it('fires blur event', () => {
Expand Down

0 comments on commit 976bc96

Please sign in to comment.