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

Commit

Permalink
Merge branch 'refactor/chips'
Browse files Browse the repository at this point in the history
  • Loading branch information
matsp committed Apr 24, 2018
2 parents c69d1a3 + b21461f commit d262bab
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
37 changes: 32 additions & 5 deletions components/chips/Chip.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<template>
<div
class="mdc-chip"
tabindex="0">
tabindex="0"
@MDCChip:interaction="onInteraction()">
<slot
name="leadingIcon"
v-if="$slots['leadingIcon']"/>
Expand Down Expand Up @@ -32,21 +33,47 @@ import themeClassMixin from '../base/themeClassMixin.js'
export default {
mixins: [themeClassMixin],
model: {
props: 'selected',
event: 'change'
},
props: {
selected: {
type: Boolean,
default: false
}
},
data () {
return {
mdcChip: null,
slotOberserver: null
mdcChip: undefined,
slotObserver: undefined
}
},
computed: {
model: {
get () {
return this.selected
},
set (value) {
this.$emit('change', value)
}
}
},
mounted () {
this.updateSlots()
this.slotOberserver = new MutationObserver( () => this.updateSlots())
this.slotOberserver.observe(this.$el, {
this.slotObserver = new MutationObserver( () => this.updateSlots())
this.slotObserver.observe(this.$el, {
childList: true,
subtree: true
})
},
beforeDestroy () {
this.slotObserver.disconnect()
},
methods: {
onInteraction () {
this.model = this.mdcChip.isSelected()
},
updateSlots () {
if (this.$slots.leadingIcon) {
this.$slots.leadingIcon.map((n) => {
Expand Down
7 changes: 1 addition & 6 deletions components/chips/ChipSet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default {
},
data () {
return {
mdcChipSet: null
mdcChipSet: undefined
}
},
computed: {
Expand All @@ -38,11 +38,6 @@ export default {
},
mounted () {
this.mdcChipSet = MDCChipSet.attachTo(this.$el)
},
methods: {
getSelectedChips () {
return this.mdcChipSet.foundation_.selectedChips_
}
}
}
</script>
4 changes: 0 additions & 4 deletions components/chips/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
| choice | Boolean | false | single selection chips in set |
| filter | Boolean | false | multiple selection chips in set |

| Method | Description |
|--------|-------------|
| getSelectedChips | returns all selected chips of the set as array |

## Chip

### Slots
Expand Down
7 changes: 6 additions & 1 deletion demo/views/ChipsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<m-layout-grid-cell :span="12">
<m-typo-title>Choice</m-typo-title>
<m-chip-set choice>
<m-chip>Chip #1</m-chip>
<m-chip v-model="choiceSelected">Chip #1</m-chip>
<m-chip>Chip #2</m-chip>
<m-chip>Chip #3</m-chip>
</m-chip-set>
Expand Down Expand Up @@ -64,6 +64,11 @@ import Chips from '../../dist/chips'
Vue.use(Chips)
export default {
data () {
return {
choiceSelected: false
}
}
}
</script>

Expand Down

0 comments on commit d262bab

Please sign in to comment.