Skip to content

Commit 0ed8ae6

Browse files
committed
chore: more logic
1 parent cf95331 commit 0ed8ae6

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

src/SelectInput/Input.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>((props, ref) => {
108108
// ============================= Render =============================
109109
return (
110110
<input
111+
type={mode === 'combobox' ? 'text' : 'search'}
111112
{...restProps}
112113
ref={inputRef}
113114
style={

src/utils/keyUtil.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function isValidateOpenKey(currentKeyCode: number): boolean {
2424
KeyCode.CONTEXT_MENU,
2525
// Arrow keys - should not trigger open when navigating in input
2626
KeyCode.UP,
27-
KeyCode.DOWN,
27+
// KeyCode.DOWN,
2828
KeyCode.LEFT,
2929
KeyCode.RIGHT,
3030
// F1-F12

tests/Select.test.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ import {
3535
describe('Select.Basic', () => {
3636
injectRunAllTimers(jest);
3737

38+
beforeEach(() => {
39+
jest.useFakeTimers();
40+
});
41+
42+
afterEach(() => {
43+
jest.clearAllTimers();
44+
jest.useRealTimers();
45+
});
46+
3847
allowClearTest(undefined, '903');
3948
focusTest('single', {});
4049
blurTest('single');
@@ -786,14 +795,16 @@ describe('Select.Basic', () => {
786795
});
787796

788797
[KeyCode.ENTER, KeyCode.DOWN].forEach((keyCode) => {
789-
it('open on key press', () => {
798+
it(`open on key press: ${keyCode}`, () => {
790799
const { container } = render(<Select />);
791800
keyDown(container.querySelector('input'), keyCode);
792801
expectOpen(container);
793802
});
794803
});
795804

796805
it('close on ESC', () => {
806+
jest.useFakeTimers();
807+
797808
const onKeyDown = jest.fn();
798809
const { container } = render(
799810
<div onKeyDown={onKeyDown}>
@@ -805,14 +816,22 @@ describe('Select.Basic', () => {
805816
const inputEle = container.querySelector('input');
806817
fireEvent.change(inputEle, { target: { value: 'foo' } });
807818
keyDown(inputEle, KeyCode.ESC);
819+
act(() => {
820+
jest.runAllTimers();
821+
});
808822

809823
expect(inputEle.value).toBe('');
810824
expectOpen(container, false);
811825
expect(onKeyDown).toHaveBeenCalledTimes(0);
812826

813827
// should keep propagation when optionList is closed
814828
keyDown(inputEle, KeyCode.ESC);
829+
act(() => {
830+
jest.runAllTimers();
831+
});
815832
expect(onKeyDown).toHaveBeenCalledTimes(1);
833+
834+
jest.useRealTimers();
816835
});
817836

818837
it('not open when system key down', () => {

tests/utils/common.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ export function expectOpen(wrapper: any, open: boolean = true) {
1919
export function toggleOpen(wrapper: any) {
2020
if (wrapper instanceof HTMLElement) {
2121
fireEvent.mouseDown(wrapper.querySelector('.rc-select'));
22+
act(() => {
23+
jest.runAllTimers();
24+
});
2225
return;
2326
}
2427
wrapper.find('.rc-select').simulate('mousedown');
@@ -27,6 +30,9 @@ export function toggleOpen(wrapper: any) {
2730
export function selectItem(wrapper: any, index: number = 0) {
2831
if (wrapper instanceof HTMLElement) {
2932
fireEvent.click(wrapper.querySelectorAll('.rc-select-item-option-content')[index]);
33+
act(() => {
34+
jest.runAllTimers();
35+
});
3036
return;
3137
}
3238
wrapper.find('div.rc-select-item-option-content').at(index).simulate('click');

0 commit comments

Comments
 (0)