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

Commit

Permalink
feat(chip): 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 e0cac12 commit cfbf749
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions components/chips/Chip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,36 @@ export default {
mixins: [themeClassMixin],
data () {
return {
mdcChip: null
mdcChip: null,
slotOberserver: null
}
},
mounted () {
if (this.$slots.leadingIcon) {
this.$slots.leadingIcon.map((n) => {
n.elm.classList.add('mdc-chip__icon')
n.elm.classList.add('mdc-chip__icon--leading')
})
}
this.updateSlots()
this.slotOberserver = new MutationObserver( () => this.updateSlots())
this.slotOberserver.observe(this.$el, {
childList: true,
subtree: true
})
},
methods: {
updateSlots () {
if (this.$slots.leadingIcon) {
this.$slots.leadingIcon.map((n) => {
n.elm.classList.add('mdc-chip__icon')
n.elm.classList.add('mdc-chip__icon--leading')
})
}
if (this.$slots.trailingIcon) {
this.$slots.trailingIcon.map((n) => {
n.elm.classList.add('mdc-chip__icon')
n.elm.classList.add('mdc-chip__icon--trailing')
n.elm.setAttribute('role', 'button')
n.elm.setAttribute('tabindex', '0')
})
if (this.$slots.trailingIcon) {
this.$slots.trailingIcon.map((n) => {
n.elm.classList.add('mdc-chip__icon')
n.elm.classList.add('mdc-chip__icon--trailing')
n.elm.setAttribute('role', 'button')
n.elm.setAttribute('tabindex', '0')
})
}
}
// this done by MDCChipSet:
// this.mdcChip = MDCChip.attachTo(this.$el)
}
}
</script>

0 comments on commit cfbf749

Please sign in to comment.