Skip to content

Commit

Permalink
Merge 9f7a159 into ed77ce1
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ authored Mar 3, 2021
2 parents ed77ce1 + 9f7a159 commit 816ae73
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
18 changes: 12 additions & 6 deletions src/generate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ import type {
SingleType,
OnClear,
SelectSource,
CustomTagProps} from './interface/generator';
import {
INTERNAL_PROPS_MARK
CustomTagProps,
} from './interface/generator';
import { INTERNAL_PROPS_MARK } from './interface/generator';
import type { OptionListProps, RefOptionListProps } from './OptionList';
import { toInnerValue, toOuterValues, removeLastEnabledValue, getUUID } from './utils/commonUtil';
import TransBtn from './TransBtn';
Expand Down Expand Up @@ -761,9 +760,16 @@ export default function generateSelector<
const clearLock = getClearLock();
const { which } = event;

// We only manage open state here, close logic should handle by list component
if (!mergedOpen && which === KeyCode.ENTER) {
onToggleOpen(true);
if (which === KeyCode.ENTER) {
// Do not submit form when type in the input
if (mode !== 'combobox') {
event.preventDefault();
}

// We only manage open state here, close logic should handle by list component
if (!mergedOpen) {
onToggleOpen(true);
}
}

setClearLock(!!mergedSearchValue);
Expand Down
25 changes: 14 additions & 11 deletions tests/Tags.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ describe('Select.Tags', () => {
});

describe('OptGroup', () => {
const createSelect = props => (
const createSelect = (props) => (
<div>
<Select mode="tags" {...props}>
<OptGroup key="Manager" label="Manager">
Expand Down Expand Up @@ -407,18 +407,21 @@ describe('Select.Tags', () => {

it('correctly handles the `tabIndex` prop', () => {
const wrapper = mount(<Select mode="tags" tabIndex={0} />);
expect(
wrapper
.find('.rc-select')
.getDOMNode()
.getAttribute('tabindex'),
).toBeNull();
expect(wrapper.find('.rc-select').getDOMNode().getAttribute('tabindex')).toBeNull();

expect(
wrapper
.find('input.rc-select-selection-search-input')
.getDOMNode()
.getAttribute('tabindex'),
wrapper.find('input.rc-select-selection-search-input').getDOMNode().getAttribute('tabindex'),
).toBe('0');
});

it('press enter should not submit form', () => {
const wrapper = mount(<Select mode="tags" open={false} />);
const preventDefault = jest.fn();
wrapper.find('input').simulate('keyDown', {
which: KeyCode.ENTER,
preventDefault,
});

expect(preventDefault).toHaveBeenCalled();
});
});
2 changes: 0 additions & 2 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ declare module 'rc-menu';

declare module 'rc-util/lib/Children/toArray';

declare module 'rc-util/lib/KeyCode';

declare module 'dom-scroll-into-view';

declare module 'rc-trigger';

0 comments on commit 816ae73

Please sign in to comment.