Skip to content

Commit 5e5551a

Browse files
author
weilei
committed
refactor(Conversations): 移除未使用的菜单属性和优化下拉菜单样式
- 移除多个未使用的菜单相关属性(menuOffset, menuMaxHeight, menuClassName, menuTeleported) - 优化下拉菜单箭头的隐藏逻辑,使用更通用的选择器 - 修复菜单项悬停样式选择器问题 - 统一事件命名风格(menu-command)
1 parent 6d892b6 commit 5e5551a

File tree

2 files changed

+19
-52
lines changed
  • packages/element-ui-x/src/components/Conversations/src

2 files changed

+19
-52
lines changed

packages/element-ui-x/src/components/Conversations/src/components/item.vue

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,18 @@
4343
class="el-x-conversation-label"
4444
:class="{ 'text-gradient': isTextOverflow(item.label) }"
4545
:style="labelStyle"
46-
>{{ item.label }}</span
4746
>
47+
{{ item.label }}
48+
</span>
4849
</el-tooltip>
4950
<span
5051
v-else
5152
class="el-x-conversation-label"
5253
:class="{ 'text-gradient': isTextOverflow(item.label) }"
5354
:style="labelStyle"
54-
>{{ item.label }}</span
5555
>
56+
{{ item.label }}
57+
</span>
5658
</div>
5759
</slot>
5860
</div>
@@ -76,14 +78,6 @@
7678
<el-dropdown
7779
trigger="click"
7880
:placement="menuPlacement"
79-
:offset="menuOffset"
80-
:teleported="menuTeleported"
81-
:popper-class="
82-
menuClassName
83-
? `el-x-conversation-dropdown-menu ${menuClassName}`
84-
: 'el-x-conversation-dropdown-menu'
85-
"
86-
:max-height="menuMaxHeight"
8781
:disabled="item.disabled"
8882
@visible-change="updateMenuStatus"
8983
@command="onMenuCommand"
@@ -113,8 +107,9 @@
113107
:divided="menuItem.divided"
114108
:command="menuItem.command"
115109
:style="menuItem.menuItemStyle"
116-
>{{ menuItem.label }}</el-dropdown-item
117110
>
111+
{{ menuItem.label }}
112+
</el-dropdown-item>
118113
</slot>
119114
</el-dropdown-menu>
120115
</el-dropdown>
@@ -185,14 +180,7 @@
185180
type: String,
186181
default: 'bottom-start',
187182
},
188-
menuOffset: {
189-
type: Number,
190-
default: 50,
191-
},
192-
menuMaxHeight: {
193-
type: Number,
194-
default: undefined,
195-
},
183+
196184
menuStyle: {
197185
type: Object,
198186
default: () => ({}),
@@ -201,14 +189,6 @@
201189
type: Boolean,
202190
default: false,
203191
},
204-
menuClassName: {
205-
type: String,
206-
default: '',
207-
},
208-
menuTeleported: {
209-
type: Boolean,
210-
default: true,
211-
},
212192
active: {
213193
type: Boolean,
214194
default: false,
@@ -306,17 +286,19 @@
306286
// 延迟执行,确保菜单已经渲染完成
307287
// 展开菜单时候 决定隐藏箭头
308288
this.$nextTick(() => {
309-
// 获取页面的所有 conversation-dropdown-menu 组件
310-
const dropdownMenu = document.querySelectorAll('.el-x-conversation-dropdown-menu');
289+
// 获取页面的所有 el-dropdown-menu el-popper 组件
290+
const dropdownMenu = document.querySelectorAll('.el-dropdown-menu.el-popper');
291+
console.log(dropdownMenu);
292+
311293
if (dropdownMenu.length === 0) {
312294
return;
313295
}
314296
dropdownMenu.forEach(dropdownMenuItem => {
315-
// 将它子元素中所有 el-popper__arrow 元素的 display 设置为 none
297+
// 将它子元素中所有 popper__arrow 元素的 display 设置为 none
316298
// 如果 dropdownMenuItem 存在,且display 不为 none
317299
if (dropdownMenuItem && dropdownMenuItem.style.display !== 'none') {
318300
// 隐藏箭头
319-
const arrows = dropdownMenuItem.querySelectorAll('.el-popper__arrow');
301+
const arrows = dropdownMenuItem.querySelectorAll('.popper__arrow');
320302
if (arrows.length === 0) {
321303
return;
322304
}
@@ -325,9 +307,8 @@
325307
});
326308
327309
// 设置 .el-dropdown-menu__item 悬停样式
328-
const items = dropdownMenuItem.querySelectorAll(
329-
'.el-dropdown-menu__item:not(.is-disabled)',
330-
);
310+
const items = dropdownMenuItem.querySelectorAll('.el-dropdown-menu__item');
311+
console.log('items', items);
331312
if (items.length === 0) {
332313
return;
333314
}

packages/element-ui-x/src/components/Conversations/src/main.vue

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,8 @@
5858
:menu="menu"
5959
:show-built-in-menu="showBuiltInMenu"
6060
:menu-placement="menuPlacement"
61-
:menu-offset="menuOffset"
62-
:menu-max-height="menuMaxHeight"
6361
:menu-style="menuStyle"
6462
:menu-show-arrow="menuShowArrow"
65-
:menu-class-name="menuClassName"
66-
:menu-teleported="menuTeleported"
6763
@click="handleClick(item)"
6864
@menu-command="handleMenuItemClick"
6965
>
@@ -122,12 +118,8 @@
122118
:menu="menu"
123119
:show-built-in-menu="showBuiltInMenu"
124120
:menu-placement="menuPlacement"
125-
:menu-offset="menuOffset"
126-
:menu-max-height="menuMaxHeight"
127121
:menu-style="menuStyle"
128122
:menu-show-arrow="menuShowArrow"
129-
:menu-class-name="menuClassName"
130-
:menu-teleported="menuTeleported"
131123
@click="handleClick(item)"
132124
@menu-command="handleMenuItemClick"
133125
>
@@ -287,10 +279,7 @@
287279
type: String,
288280
default: 'bottom-start',
289281
},
290-
menuOffset: {
291-
type: Number,
292-
default: 50,
293-
},
282+
294283
menuShowArrow: {
295284
type: Boolean,
296285
default: false,
@@ -299,15 +288,12 @@
299288
type: String,
300289
default: '',
301290
},
302-
menuTeleported: {
303-
type: Boolean,
304-
default: true,
305-
},
291+
306292
menuStyle: {
307293
type: Object,
308294
default: () => ({}),
309295
},
310-
menuMaxHeight: Number,
296+
311297
loadMoreLoading: {
312298
type: Boolean,
313299
default: false,
@@ -578,7 +564,7 @@
578564
},
579565
580566
handleMenuItemClick(command, item) {
581-
this.$emit('menuCommand', command, item);
567+
this.$emit('menu-command', command, item);
582568
},
583569
584570
bindGroupRef(el, item) {

0 commit comments

Comments
 (0)