Skip to content

Commit

Permalink
fix(switch): make alignEnd prop reactive
Browse files Browse the repository at this point in the history
fix #231
  • Loading branch information
stasson committed Jan 29, 2018
1 parent 8b11823 commit c5cde20
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions components/switch/mdc-switch.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
<template>
<div :class="formFieldClasses" class="mdc-switch-wrapper">
<div class="mdc-switch" ref=root
:class="{ 'mdc-switch--disabled': disabled }">
<input ref="control" type="checkbox" :name="name" :id="_uid"
class="mdc-switch__native-control"
@change="onChanged" :checked="checked" :disabled="disabled"/>
<div class="mdc-switch__background">
<div class="mdc-switch__knob"></div>
<div class="mdc-switch-wrapper"
:class="{
'mdc-form-field': this.hasLabel,
'mdc-form-field--align-end': this.hasLabel && this.alignEnd
}" >

<div class="mdc-switch"
:class="{'mdc-switch--disabled': disabled }">
<input ref="control" type="checkbox"
:name="name" :id="_uid"
class="mdc-switch__native-control"
:checked="checked"
:disabled="disabled"
@change="onChanged" />

<div class="mdc-switch__background">
<div class="mdc-switch__knob"></div>
</div>

</div>

<label :for="_uid" v-if="hasLabel"
class="mdc-switch-label">
<slot>{{label}}</slot>
</label>

</div>
<label ref="label" :for="_uid"><slot>{{label}}</slot></label>
</div>
</template>

<script>
Expand All @@ -31,20 +46,10 @@ export default {
'value': { type: String, default () { return 'on' } },
'name': String
},
data () {
return {
formFieldClasses: {
'mdc-form-field': this.label,
'mdc-form-field--align-end': this.label && this.alignEnd
}
}
},
watch: {
'disabled' (value) {
this.foundation.setDisabled(value)
}
},
computed: {
hasLabel () {
return this.label || this.$slots.default
}
},
methods: {
onChanged (event) {
Expand Down

0 comments on commit c5cde20

Please sign in to comment.