Skip to content
This repository has been archived by the owner on Nov 30, 2020. It is now read-only.

Commit

Permalink
feat(card): Use MutationObserver for reactive slot updates (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
matsp committed Apr 23, 2018
1 parent 58c0ea4 commit b24651c
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions components/card/Card.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,29 @@ export default {
}
},
mounted () {
if (this.$slots.actionButtons) {
this.$slots.actionButtons.map((n) => {
n.elm.classList.add('mdc-card__action')
n.elm.classList.add('mdc-card__action--button')
})
}
if (this.$slots.actionIcons) {
this.$slots.actionIcons.map((n) => {
n.elm.classList.add('mdc-card__action')
n.elm.classList.add('mdc-card__action--icon')
n.elm.setAttribute('tabindex', '0')
n.elm.setAttribute('role', 'button')
})
this.updateSlots()
this.slotOberserver = new MutationObserver( () => this.updateSlots())
this.slotOberserver.observe(this.$el, {
childList: true,
subtree: true
})
},
methods: {
updateSlots () {
if (this.$slots.actionButtons) {
this.$slots.actionButtons.map((n) => {
n.elm.classList.add('mdc-card__action')
n.elm.classList.add('mdc-card__action--button')
})
}
if (this.$slots.actionIcons) {
this.$slots.actionIcons.map((n) => {
n.elm.classList.add('mdc-card__action')
n.elm.classList.add('mdc-card__action--icon')
n.elm.setAttribute('tabindex', '0')
n.elm.setAttribute('role', 'button')
})
}
}
}
}
Expand Down

0 comments on commit b24651c

Please sign in to comment.