Skip to content

Commit

Permalink
fix: remove onMouseDown to resolve popover close
Browse files Browse the repository at this point in the history
  • Loading branch information
geekrainy committed Mar 23, 2021
1 parent 45856a8 commit 287c212
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 27 deletions.
16 changes: 5 additions & 11 deletions src/Selector/MultipleSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import classNames from 'classnames';
import pickAttrs from 'rc-util/lib/pickAttrs';
import Overflow from 'rc-overflow';
import TransBtn from '../TransBtn';
import {
import type {
LabelValueType,
DisplayLabelValueType,
RawValueType,
CustomTagProps,
DefaultValueType,
} from '../interface/generator';
import { RenderNode } from '../interface';
import { InnerSelectorProps } from '.';
import type { RenderNode } from '../interface';
import type { InnerSelectorProps } from '.';
import Input from './Input';
import useLayoutEffect from '../hooks/useLayoutEffect';

Expand All @@ -35,11 +35,7 @@ interface SelectorProps extends InnerSelectorProps {
onSelect: (value: RawValueType, option: { selected: boolean }) => void;
}

const onPreventMouseDown = (event: React.MouseEvent) => {
event.preventDefault();
event.stopPropagation();
};
const SelectSelector: React.FC<SelectorProps> = props => {
const SelectSelector: React.FC<SelectorProps> = (props) => {
const {
id,
prefixCls,
Expand Down Expand Up @@ -107,7 +103,6 @@ const SelectSelector: React.FC<SelectorProps> = props => {
{closable && (
<TransBtn
className={`${selectionPrefixCls}-item-remove`}
onMouseDown={onPreventMouseDown}
onClick={onClose}
customizeIcon={removeIcon}
>
Expand All @@ -125,8 +120,7 @@ const SelectSelector: React.FC<SelectorProps> = props => {
closable: boolean,
onClose: React.MouseEventHandler,
) {
const onMouseDown = (e: React.MouseEvent) => {
onPreventMouseDown(e);
const onMouseDown = () => {
onToggleOpen(true);
};

Expand Down
18 changes: 11 additions & 7 deletions src/Selector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,19 @@ const Selector: React.RefForwardingComponent<RefSelectorProps, SelectorProps> =

const onMouseDown: React.MouseEventHandler<HTMLElement> = (event) => {
const inputMouseDown = getInputMouseDown();
if (event.target !== inputRef.current && !inputMouseDown) {
event.preventDefault();
}
const tagCloseMouseDown = (event.target as HTMLElement).innerText === '×';

if (!tagCloseMouseDown) {
if (event.target !== inputRef.current && !inputMouseDown) {
event.preventDefault();
}

if ((mode !== 'combobox' && (!showSearch || !inputMouseDown)) || !open) {
if (open) {
onSearch('', true, false);
if ((mode !== 'combobox' && (!showSearch || !inputMouseDown)) || !open) {
if (open) {
onSearch('', true, false);
}
onToggleOpen();
}
onToggleOpen();
}
};

Expand Down
10 changes: 1 addition & 9 deletions tests/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ export function toggleOpen(wrapper: any) {
}

export function selectItem(wrapper: any, index: number = 0) {
wrapper
.find('div.rc-select-item-option-content')
.at(index)
.simulate('click');
wrapper.find('div.rc-select-item-option-content').at(index).simulate('click');
}

export function findSelection(wrapper: any, index: number = 0) {
Expand All @@ -33,17 +30,12 @@ export function findSelection(wrapper: any, index: number = 0) {
}

export function removeSelection(wrapper: any, index: number = 0) {
const preventDefault = jest.fn();

wrapper
.find('.rc-select-selection-item')
.at(index)
.find('.rc-select-selection-item-remove')
.last()
.simulate('mousedown', { preventDefault })
.simulate('click');

expect(preventDefault).toHaveBeenCalled();
}

type Jest = typeof jest;
Expand Down

0 comments on commit 287c212

Please sign in to comment.