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

Commit 7aeccfa

Browse files
committed
fix(icon-button): Use computed properties for slot toggling
1 parent 6cd7362 commit 7aeccfa

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

components/icon-button/IconButton.vue

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
@MDCIconButtonToggle:change="$emit('change', $event.detail.isOn)">
1313
<slot v-if="isIconButton"/>
1414
<slot
15-
v-else-if="isToggleButtonViaSlots && !value"
15+
v-if="isToggleButtonViaSlots && !value"
1616
name="toggleOn"/>
1717
<slot
18-
v-else-if="isToggleButtonViaSlots && value"
18+
v-if="isToggleButtonViaSlots && value"
1919
name="toggleOff"/>
2020
</button>
2121
</template>
@@ -69,6 +69,17 @@ export default {
6969
slotObserver: undefined
7070
}
7171
},
72+
computed: {
73+
isToggleButtonViaSlots () {
74+
return this.$slots.toggleOn && this.$slots.toggleOff && !this.isIconButton
75+
},
76+
isIconButton () {
77+
return this.$slots.default
78+
},
79+
isToggleButton () {
80+
return this.toggleOnContent !== '' && this.toggleOffContent !== ''
81+
}
82+
},
7283
watch: {
7384
value (value) {
7485
if (typeof this.mdcIconButtonToggle !== 'undefined') {
@@ -94,26 +105,14 @@ export default {
94105
},
95106
methods: {
96107
update () {
97-
if ((this.isToggleButton() || this.isToggleButtonViaSlots()) && typeof this.mdcIconButtonToggle === 'undefined') {
108+
if ((this.isToggleButton || this.isToggleButtonViaSlots) && typeof this.mdcIconButtonToggle === 'undefined') {
98109
this.mdcIconButtonToggle = MDCIconButtonToggle.attachTo(this.$el)
99110
this.mdcIconButtonToggle.on = this.value
100111
}
101-
if (this.isIconButton() && typeof this.mdcRipple === 'undefined') {
112+
if (this.isIconButton && typeof this.mdcRipple === 'undefined') {
102113
this.mdcRipple = MDCRipple.attachTo(this.$el)
103114
this.mdcRipple.unbounded = true
104115
}
105-
},
106-
isIconButton () {
107-
return this.$slots.default
108-
},
109-
isToggleButton () {
110-
return this.toggleOnContent !== '' && this.toggleOffContent !== ''
111-
},
112-
isToggleButtonViaSlots () {
113-
return this.toggleOnContent === '' &&
114-
this.toggleOffContent === '' &&
115-
this.$slots.toggleOn &&
116-
this.$slots.toggleOff
117116
}
118117
}
119118
}

0 commit comments

Comments
 (0)