Skip to content

Commit

Permalink
fix(MdListItem): allow multiple actions (#1760)
Browse files Browse the repository at this point in the history
* fix(MdListItem): allow multiple actions

* refactor(MdListItem): refactor hasChildrenButtons function

* refactor(MdListItem): remove const

* feat(MdListItem): remove prefixed user-select
  • Loading branch information
Samuell1 authored Jun 11, 2018
1 parent 869389e commit 714ee9f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/components/MdList/MdListItem/MdListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import MdInteractionEvents from 'core/utils/MdInteractionEvents'
import MdRouterLinkProps from 'core/utils/MdRouterLinkProps'
import MdListItemDefault from './MdListItemDefault'
import MdListItemFakeButton from './MdListItemFakeButton'
import MdListItemButton from './MdListItemButton'
import MdListItemLink from './MdListItemLink'
import MdListItemRouter from './MdListItemRouter'
Expand All @@ -22,6 +23,10 @@
}
}
function hasChildrenButtons (childrens) {
return childrens.default.some(children => children.componentOptions && children.componentOptions.tag === 'md-button')
}
function shouldRenderButtonWithListener (listeners) {
let listenerNames = Object.keys(listeners)
let shouldRender = false
Expand All @@ -39,7 +44,7 @@
return parent && parent.$router && props.to
}
function createListComponent (props, parent, listeners) {
function createListComponent (props, parent, listeners, children) {
if (hasExpansion(props)) {
return MdListItemExpand
}
Expand All @@ -62,6 +67,9 @@
}
if (shouldRenderButtonWithListener(listeners)) {
if (hasChildrenButtons(children)) {
return MdListItemFakeButton
}
return MdListItemButton
}
Expand All @@ -76,7 +84,7 @@
},
render (createElement, { parent, props, listeners, data, slots }) {
let children = slots()
let listComponent = createListComponent(props, parent, listeners)
let listComponent = createListComponent(props, parent, listeners, children)
let staticClass = 'md-list-item'
if (data.staticClass) {
Expand Down
16 changes: 16 additions & 0 deletions src/components/MdList/MdListItem/MdListItemFakeButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<template>
<div class="md-list-item-fake-button" :disabled="disabled">
<md-list-item-content :md-disabled="isDisabled">
<slot />
</md-list-item-content>
</div>
</template>

<script>
import MdListItemMixin from './MdListItemMixin'
export default {
name: 'MdListItemFakeButton',
mixins: [MdListItemMixin]
}
</script>

0 comments on commit 714ee9f

Please sign in to comment.