Skip to content

Commit

Permalink
fix: Search focus lost compositing status (#548)
Browse files Browse the repository at this point in the history
* fix: compositin status lost when search to open dropdown

close ant-design/ant-design#26790

* Add test case
  • Loading branch information
afc163 committed Sep 17, 2020
1 parent ba94960 commit 32e1861
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
3 changes: 1 addition & 2 deletions examples/single.tsx
Expand Up @@ -66,15 +66,14 @@ class Test extends React.Component {
id="my-select"
value={value}
placeholder="placeholder"
showSearch={false}
showSearch
style={{ width: 500 }}
onBlur={this.onBlur}
onFocus={this.onFocus}
onSearch={this.onSearch}
allowClear
optionFilterProp="text"
onChange={this.onChange}
backfill
onPopupScroll={() => {
console.log('Scroll!');
}}
Expand Down
2 changes: 1 addition & 1 deletion src/Selector/SingleSelector.tsx
Expand Up @@ -40,7 +40,7 @@ const SingleSelector: React.FC<SelectorProps> = props => {
const [inputChanged, setInputChanged] = React.useState(false);

const combobox = mode === 'combobox';
const inputEditable = combobox || (showSearch && open);
const inputEditable = combobox || showSearch;
const item = values[0];

let inputValue: string = searchValue || '';
Expand Down
15 changes: 15 additions & 0 deletions tests/Select.test.tsx
Expand Up @@ -243,6 +243,21 @@ describe('Select.Basic', () => {
expect(findSelection(wrapper).text()).toBe('1');
});

it('search input should be editable initially', () => {
const wrapper = mount(
<Select showSearch>
<Option value="1">One</Option>
<Option value="2">Two</Option>
</Select>,
);
expect(
wrapper
.find('input')
.getDOMNode()
.getAttribute('readonly'),
).toBeFalsy();
});

it('filter options by "value" prop by default', () => {
const wrapper = mount(
<Select showSearch>
Expand Down
15 changes: 0 additions & 15 deletions tests/__snapshots__/Select.test.tsx.snap
Expand Up @@ -254,11 +254,8 @@ exports[`Select.Basic render renders aria-attributes correctly 1`] = `
aria-owns="undefined_list"
autocomplete="off"
class="antd-selection-search-input"
readonly=""
role="combobox"
style="opacity:0"
type="search"
unselectable="on"
value=""
/>
</span>
Expand Down Expand Up @@ -312,11 +309,8 @@ exports[`Select.Basic render renders correctly 1`] = `
aria-owns="undefined_list"
autocomplete="off"
class="antd-selection-search-input"
readonly=""
role="combobox"
style="opacity:0"
type="search"
unselectable="on"
value=""
/>
</span>
Expand Down Expand Up @@ -372,11 +366,8 @@ exports[`Select.Basic render renders data-attributes correctly 1`] = `
aria-owns="undefined_list"
autocomplete="off"
class="antd-selection-search-input"
readonly=""
role="combobox"
style="opacity:0"
type="search"
unselectable="on"
value=""
/>
</span>
Expand Down Expand Up @@ -432,11 +423,8 @@ exports[`Select.Basic render renders disabled select correctly 1`] = `
autocomplete="off"
class="antd-selection-search-input"
disabled=""
readonly=""
role="combobox"
style="opacity:0"
type="search"
unselectable="on"
value=""
/>
</span>
Expand Down Expand Up @@ -663,11 +651,8 @@ exports[`Select.Basic render renders role prop correctly 1`] = `
aria-owns="undefined_list"
autocomplete="off"
class="antd-selection-search-input"
readonly=""
role="button"
style="opacity:0"
type="search"
unselectable="on"
value=""
/>
</span>
Expand Down

1 comment on commit 32e1861

@vercel
Copy link

@vercel vercel bot commented on 32e1861 Sep 17, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.