Skip to content

Commit 714ee9f

Browse files
authored
fix(MdListItem): allow multiple actions (#1760)
* fix(MdListItem): allow multiple actions * refactor(MdListItem): refactor hasChildrenButtons function * refactor(MdListItem): remove const * feat(MdListItem): remove prefixed user-select
1 parent 869389e commit 714ee9f

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/components/MdList/MdListItem/MdListItem.vue

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import MdInteractionEvents from 'core/utils/MdInteractionEvents'
33
import MdRouterLinkProps from 'core/utils/MdRouterLinkProps'
44
import MdListItemDefault from './MdListItemDefault'
5+
import MdListItemFakeButton from './MdListItemFakeButton'
56
import MdListItemButton from './MdListItemButton'
67
import MdListItemLink from './MdListItemLink'
78
import MdListItemRouter from './MdListItemRouter'
@@ -22,6 +23,10 @@
2223
}
2324
}
2425
26+
function hasChildrenButtons (childrens) {
27+
return childrens.default.some(children => children.componentOptions && children.componentOptions.tag === 'md-button')
28+
}
29+
2530
function shouldRenderButtonWithListener (listeners) {
2631
let listenerNames = Object.keys(listeners)
2732
let shouldRender = false
@@ -39,7 +44,7 @@
3944
return parent && parent.$router && props.to
4045
}
4146
42-
function createListComponent (props, parent, listeners) {
47+
function createListComponent (props, parent, listeners, children) {
4348
if (hasExpansion(props)) {
4449
return MdListItemExpand
4550
}
@@ -62,6 +67,9 @@
6267
}
6368
6469
if (shouldRenderButtonWithListener(listeners)) {
70+
if (hasChildrenButtons(children)) {
71+
return MdListItemFakeButton
72+
}
6573
return MdListItemButton
6674
}
6775
@@ -76,7 +84,7 @@
7684
},
7785
render (createElement, { parent, props, listeners, data, slots }) {
7886
let children = slots()
79-
let listComponent = createListComponent(props, parent, listeners)
87+
let listComponent = createListComponent(props, parent, listeners, children)
8088
let staticClass = 'md-list-item'
8189
8290
if (data.staticClass) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<template>
2+
<div class="md-list-item-fake-button" :disabled="disabled">
3+
<md-list-item-content :md-disabled="isDisabled">
4+
<slot />
5+
</md-list-item-content>
6+
</div>
7+
</template>
8+
9+
<script>
10+
import MdListItemMixin from './MdListItemMixin'
11+
12+
export default {
13+
name: 'MdListItemFakeButton',
14+
mixins: [MdListItemMixin]
15+
}
16+
</script>

0 commit comments

Comments
 (0)