Skip to content

Commit

Permalink
fix: [Dropdown] events key
Browse files Browse the repository at this point in the history
  • Loading branch information
KouSum committed Jan 9, 2024
1 parent 3dc2b6f commit c34bac0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
25 changes: 16 additions & 9 deletions packages/semi-ui-vue/src/components/dropdown/dropdownItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { noop } from 'lodash';
import {vuePropsMake} from "../PropTypes";
import {useDropdownContext} from "./context/Consumer";
import {ComponentObjectPropsOptions} from "vue";
import type {Events} from "vue";

export type Type = 'primary' | 'secondary' | 'tertiary' | 'warning' | 'danger';

Expand All @@ -17,9 +18,9 @@ export interface DropdownItemProps extends BaseProps {
disabled?: boolean;
selected?: boolean;
onClick?: (payload: MouseEvent) => void;
onMouseEnter?: (payload: MouseEvent) => void;
onMouseLeave?: (payload: MouseEvent) => void;
onContextMenu?: (payload: MouseEvent) => void;
onMouseenter?: (payload: MouseEvent) => void;
onMouseleave?: (payload: MouseEvent) => void;
onContextmenu?: (payload: MouseEvent) => void;
type?: Type;
active?: boolean;
icon?: JSX.Element;
Expand All @@ -36,9 +37,9 @@ const propTypes: ComponentObjectPropsOptions<DropdownItemProps> = {
disabled: PropTypes.bool,
selected: PropTypes.bool,
onClick: PropTypes.func as PropType<DropdownItemProps['onClick']>,
onMouseEnter: PropTypes.func as PropType<DropdownItemProps['onMouseEnter']>,
onMouseLeave: PropTypes.func as PropType<DropdownItemProps['onMouseLeave']>,
onContextMenu: PropTypes.func as PropType<DropdownItemProps['onContextMenu']>,
onMouseenter: PropTypes.func as PropType<DropdownItemProps['onMouseenter']>,
onMouseleave: PropTypes.func as PropType<DropdownItemProps['onMouseleave']>,
onContextmenu: PropTypes.func as PropType<DropdownItemProps['onContextmenu']>,
className: PropTypes.string,
style: PropTypes.object,
forwardRef: [PropTypes.object, PropTypes.func],
Expand Down Expand Up @@ -89,11 +90,17 @@ const DropdownItem = defineComponent<DropdownItemProps>((props, {slots}) => {
[`${prefixCls}-item-active`]: active,
});

const events = {};
const events:Partial<{
onClick: (e:MouseEvent)=>void;
onMousedown: (e:MouseEvent)=>void;
onMouseenter: (e:MouseEvent)=>void;
onMouseleave: (e:MouseEvent)=>void;
onContextmenu: (e:MouseEvent)=>void;
}> = {};
if (!disabled) {
['onClick', 'onMouseEnter', 'onMouseLeave', 'onContextMenu'].forEach(eventName => {
['onClick', 'onMouseenter', 'onMouseleave', 'onContextmenu'].forEach(eventName => {
if (eventName === "onClick") {
events["onMouseDown"] = props[eventName];
events.onMousedown = props[eventName];
} else {
events[eventName] = props[eventName];
}
Expand Down
9 changes: 6 additions & 3 deletions packages/semi-ui-vue/src/components/navigation/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,10 @@ const NavItem = defineComponent<NavItemProps>((props, {attrs, slots}) => {
);
};

const handleClick = (e: MouseEvent) => foundation.handleClick(e);
const handleClick = (e: MouseEvent) => {
console.log(e)
foundation.handleClick(e)
};
const handleKeyPress = (e: KeyboardEvent) => foundation.handleKeyPress(e);


Expand Down Expand Up @@ -278,8 +281,8 @@ const NavItem = defineComponent<NavItemProps>((props, {attrs, slots}) => {
ref={setItemRef}
className={popoverItemCls}
onClick={handleClick}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
onMouseenter={onMouseEnter}
onMouseleave={onMouseLeave}
disabled={disabled}
onKeyDown={handleKeyPress}
>
Expand Down
1 change: 1 addition & 0 deletions packages/semi-ui-vue/src/components/navigation/SubNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ const SubNav = defineComponent<SubNavProps>((props, {}) => {
onVisibleChange={handleDropdownVisible}
{...dropdownProps}
>
{/*用_elem 会导致无限循环*/}
{elem}
</Dropdown>
) : (
Expand Down

0 comments on commit c34bac0

Please sign in to comment.