Skip to content

Commit

Permalink
fix(dropdown): dropdown keydown error
Browse files Browse the repository at this point in the history
  • Loading branch information
berber1016 committed Dec 8, 2021
1 parent eb25fc2 commit 5fd461d
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions src/dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { cloneElement, Children, forwardRef } from 'react';
import classnames from 'classnames';
import { usePrefixCls } from '@gio-design/utils';
import { isFunction, isUndefined } from 'lodash';
import { isFunction, isUndefined, noop } from 'lodash';
import DropdownProps from './interface';
import useControlledState from '../utils/hooks/useControlledState';
import Popover from '../popover';
Expand Down Expand Up @@ -56,19 +56,9 @@ export const Dropdown = forwardRef<HTMLDivElement, DropdownProps>((props, ref) =
}
};
const onClick = close;
const onKeyDown = ({ key }: React.KeyboardEvent<HTMLDivElement>) => {
if ([' ', 'Enter', 'Escape'].includes(key)) {
close();
}
};

return (
<div
role="button"
ref={ref}
tabIndex={0}
onClick={isUndefined(visible) ? onClick : undefined}
onKeyDown={onKeyDown}
>
<div role="none" ref={ref} onKeyDown={noop} onClick={isUndefined(visible) ? onClick : noop}>
{contentNode}
</div>
);
Expand Down

0 comments on commit 5fd461d

Please sign in to comment.