From d5a3f9fa769b08ee9f0824b22d72839c8d809463 Mon Sep 17 00:00:00 2001 From: zombiej Date: Tue, 14 May 2019 21:03:48 +0800 Subject: [PATCH 1/3] delay to close in combobox --- src/Select.tsx | 10 +++++++++- tests/Select.combobox.spec.tsx | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/Select.tsx b/src/Select.tsx index 098be896c..c88b7a048 100644 --- a/src/Select.tsx +++ b/src/Select.tsx @@ -371,7 +371,7 @@ class Select extends React.Component, ISelectState> { }; public onInputKeyDown = (event: React.ChangeEvent | KeyboardEvent) => { - const { disabled, combobox } = this.props; + const { disabled, combobox, defaultActiveFirstOption } = this.props; if (disabled) { return; } @@ -406,6 +406,13 @@ class Select extends React.Component, ISelectState> { if (isRealOpen || !combobox) { event.preventDefault(); } + + // Hard close popup to avoid lock of non option in combobox mode + if (isRealOpen && combobox && defaultActiveFirstOption === false) { + setTimeout(() => { + this.setOpenState(false); + }); + } } else if (keyCode === KeyCode.ESC) { if (state.open) { this.setOpenState(false); @@ -800,6 +807,7 @@ class Select extends React.Component, ISelectState> { backfillValue: '', }; // clear search input value when open is false in singleMode. + // https://github.com/ant-design/ant-design/issues/16572 if (!open && isSingleMode(props) && props.showSearch) { this.setInputValue('', fireSearch); } diff --git a/tests/Select.combobox.spec.tsx b/tests/Select.combobox.spec.tsx index f75e1fb77..f2bd83363 100644 --- a/tests/Select.combobox.spec.tsx +++ b/tests/Select.combobox.spec.tsx @@ -374,4 +374,28 @@ describe('Select.combobox', () => { .simulate('click'); expect(wrapper.find('input').prop('value')).toBe('xxx-1'); }); + + // https://github.com/ant-design/ant-design/issues/16572 + it('close when enter press without active option', () => { + jest.useFakeTimers(); + + const onDropdownVisibleChange = jest.fn(); + + const wrapper = mount + + + , + ); + + wrapper.find('input').simulate('keyDown', { + keyCode: KeyCode.ENTER, + }); + + jest.runAllTimers(); + wrapper.update(); + expect(onDropdownVisibleChange).toBeCalledWith(false); + + jest.useRealTimers(); + }); }); From 4a1278ee760495e8cfe7f7418be4498f4c212981 Mon Sep 17 00:00:00 2001 From: zombiej Date: Tue, 14 May 2019 21:08:23 +0800 Subject: [PATCH 2/3] update package.json --- package.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 634cc93d4..b00a54aa0 100644 --- a/package.json +++ b/package.json @@ -28,9 +28,9 @@ "port": 8003 }, "scripts": { - "build": "rc-tools run storybook-build", + "build": "rc-tools run build", "compile": "rc-tools run compile --babel-runtime", - "gh-pages": "npm run build && rc-tools run storybook-gh-pages", + "gh-pages": "rc-tools run gh-pages", "start": "rc-tools run storybook", "pub": "rc-tools run pub --babel-runtime", "lint": "rc-tools run lint", @@ -39,10 +39,8 @@ "test": "rc-tools run test", "prepublish": "rc-tools run guard", "init-tslint": "rc-tools run gen-lint-config", - "init-storybook": "rc-tools run genStorybook", "coverage": "rc-tools run test --coverage", "pre-commit": "rc-tools run pre-commit", - "storybook": "rc-tools run storybook", "lint-staged": "lint-staged", "now-build": "npm run build" }, From 2f137bb634366eb277e87e025c82e2212e5457d2 Mon Sep 17 00:00:00 2001 From: zombiej Date: Tue, 14 May 2019 23:31:13 +0800 Subject: [PATCH 3/3] clean up --- src/Select.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Select.tsx b/src/Select.tsx index c88b7a048..56ce915fa 100644 --- a/src/Select.tsx +++ b/src/Select.tsx @@ -233,6 +233,7 @@ class Select extends React.Component, ISelectState> { public dropdownContainer: Element | null = null; public blurTimer: number | null = null; public focusTimer: number | null = null; + public comboboxTimer: number | null = null; // tslint:disable-next-line:variable-name private _focused: boolean = false; @@ -304,6 +305,7 @@ class Select extends React.Component, ISelectState> { public componentWillUnmount() { this.clearFocusTime(); this.clearBlurTime(); + this.clearComboboxTime(); if (this.dropdownContainer) { ReactDOM.unmountComponentAtNode(this.dropdownContainer); document.body.removeChild(this.dropdownContainer); @@ -409,7 +411,7 @@ class Select extends React.Component, ISelectState> { // Hard close popup to avoid lock of non option in combobox mode if (isRealOpen && combobox && defaultActiveFirstOption === false) { - setTimeout(() => { + this.comboboxTimer = setTimeout(() => { this.setOpenState(false); }); } @@ -969,6 +971,13 @@ class Select extends React.Component, ISelectState> { } }; + public clearComboboxTime = () => { + if (this.comboboxTimer) { + clearTimeout(this.comboboxTimer); + this.comboboxTimer = null; + } + }; + public updateFocusClassName = () => { const rootRef = this.rootRef; const props = this.props;