Explorar o código

fix: fix multiple dropdown not trigger click sometimes (#1793)

Co-authored-by: pointhalo <[email protected]>
代强 %!s(int64=2) %!d(string=hai) anos
pai
achega
dedefcd64d
Modificáronse 1 ficheiros con 22 adicións e 5 borrados
  1. 22 5
      packages/semi-ui/dropdown/dropdownItem.tsx

+ 22 - 5
packages/semi-ui/dropdown/dropdownItem.tsx

@@ -66,7 +66,19 @@ class DropdownItem extends BaseComponent<DropdownItemProps> {
 
 
     render() {
-        const { children, disabled, className, forwardRef, style, type, active, icon, onKeyDown, showTick, hover } = this.props;
+        const {
+            children,
+            disabled,
+            className,
+            forwardRef,
+            style,
+            type,
+            active,
+            icon,
+            onKeyDown,
+            showTick,
+            hover
+        } = this.props;
         const { showTick: contextShowTick } = this.context;
         const realShowTick = contextShowTick ?? showTick;
         const itemclass = cls(className, {
@@ -81,16 +93,20 @@ class DropdownItem extends BaseComponent<DropdownItemProps> {
         const events = {};
         if (!disabled) {
             ['onClick', 'onMouseEnter', 'onMouseLeave', 'onContextMenu'].forEach(eventName => {
-                events[eventName] = this.props[eventName];
+                if (eventName === "onClick") {
+                    events["onMouseDown"] = this.props[eventName];
+                } else {
+                    events[eventName] = this.props[eventName];
+                }
             });
         }
         let tick = null;
         switch (true) {
             case realShowTick && active:
-                tick = <IconTick />;
+                tick = <IconTick/>;
                 break;
             case realShowTick && !active:
-                tick = <IconTick style={{ color: 'transparent' }} />;
+                tick = <IconTick style={{ color: 'transparent' }}/>;
                 break;
             default:
                 tick = null;
@@ -105,7 +121,8 @@ class DropdownItem extends BaseComponent<DropdownItemProps> {
             );
         }
         return (
-            <li role="menuitem" tabIndex={-1} aria-disabled={disabled} {...events} onKeyDown={onKeyDown} ref={ref => forwardRef(ref)} className={itemclass} style={style}>
+            <li role="menuitem" tabIndex={-1} aria-disabled={disabled} {...events} onKeyDown={onKeyDown}
+                ref={ref => forwardRef(ref)} className={itemclass} style={style}>
                 {tick}
                 {iconContent}
                 {children}