element-plus [Bug Report] [Component] [dropdown-item] disabled @click仍能执行

hfyxw5xn  于 2022-11-05  发布在  其他
关注(0)|答案(3)|浏览(221)

Bug Type:Component

Environment

  • Vue Version: 3.2.33
  • Element Plus Version: 2.1.10
  • Browser / OS: UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36
  • Build Tool: Vite

Reproduction

dropdown-item设置disabled属性绑定的单击事件仍能执行,command则不会

  • el-dropdown-item

Element Plus Playground

Steps to reproduce

<template>
  <el-dropdown>
    <span class="el-dropdown-link">
      Dropdown List<el-icon class="el-icon--right"><arrow-down /></el-icon>
    </span>
    <template #dropdown>
      <el-dropdown-menu>      
        <el-dropdown-item   @click="handledisabledclick" disabled>disabled</el-dropdown-item>    
           <el-dropdown-item   @click="handleenabledclick" >enabled</el-dropdown-item>    
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>

<script lang="ts" setup>
import { ElMessage } from 'element-plus'
import { ArrowDown } from '@element-plus/icons-vue'
const handledisabledclick=()=>{
ElMessage(`disabled click`)
};
const handleenabledclick=()=>{
ElMessage(`enabled click`)
}
</script>
<style scoped>
.example-showcase .el-dropdown-link {
cursor: pointer;
color: var(--el-color-primary);
display: flex;
align-items: center;
}
</style>

What is Expected?

What is actually happening?

Additional comments

  • (empty)*
ymdaylpp

ymdaylpp1#

Since the click event is directly bound to the component, unless the native disabled property is triggered, it will be disabled, similar to el-button/el-input , this needs to be discussed

shyt4zoc

shyt4zoc2#

style disabled

.el-dropdown-menu__item.is-disabled:active{ pointer-events: none; }

baubqpgj

baubqpgj3#

这是个bug应该被修复,现目前给出以下解决方案:

  1. 使用 @haodaking 的解决方案,为禁用的 el-dropwn-menu 组件设置 CSS pointer-events 属性 (推荐)
:deep(.el-dropdown-menu__item.is-disabled:active){ pointer-events: none; }
  1. 使用 command 进行事件代理
  2. el-drop-item 外层嵌套一层 div 标签,将点击事件绑定在该 div
<div @click="clickHandler">
  <el-dropdown-item disabled>Action 2</el-dropdown-item>
</div>

相关问题