Skip to content

Commit

Permalink
Fix #56, Work on #15
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaberaldo committed May 10, 2017
1 parent d15bb74 commit 38a0ac8
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 23 deletions.
5 changes: 1 addition & 4 deletions src/components/checkbox/Checkbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
data() {
return {
newValue: this.value
newValue: this.value || this.checked
}
},
watch: {
Expand All @@ -47,9 +47,6 @@
this.$emit('input', value)
this.$parent.isCheckboxGroup && this.$parent.updateValue()
}
},
mounted() {
this.newValue = this.checked
}
}
</script>
2 changes: 1 addition & 1 deletion src/components/checkbox/CheckboxGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
methods: {
/**
* Update the checkedList property with all the Checkboxes that are active.
* This is called from Checkbox child.
* This is called from a child Checkbox.
* Emit input event to update the user v-model.
*/
updateValue() {
Expand Down
6 changes: 5 additions & 1 deletion src/components/radio/Radio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:disabled="disabled"
:checked="isChecked"
:name="name"
:value="this.value"
:value="value"
@change="changed">
<span><slot></slot></span>
</label>
Expand All @@ -25,6 +25,10 @@
}
},
methods: {
/**
* Input change listener.
* Call updateValue from parent.
*/
changed(event) {
this.$parent.updateValue(this.value, event)
}
Expand Down
13 changes: 8 additions & 5 deletions src/components/radio/RadioButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
type="button"
class="radio button"
:disabled="disabled"
:class="[isChecked ? type : '', size]"
:class="[isChecked ? type : null, size]"
@click="changed">
<slot></slot>
<input
type="radio"
:disabled="disabled"
:checked="isChecked"
:name="name"
:value="this.value">
:value="value">
</button>
</p>
</template>
Expand All @@ -31,13 +31,16 @@
},
data() {
return {
// Used internally by Radio Group
size: '',
size: null,
isChecked: false,
isRadioButton: true
isRadioButtonComponent: true // Used internally by Radio Group
}
},
methods: {
/**
* Input change listener.
* Call updateValue from parent.
*/
changed(event) {
this.$parent.updateValue(this.value, event)
}
Expand Down
24 changes: 18 additions & 6 deletions src/components/radio/RadioGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,42 @@
},
data() {
return {
isRadioGroupComponent: true, // Used internally by Radio and Radio Button
isRadioButtonGroup: false // Used internally by Radio Button
isRadioGroupComponent: true, // Used internally by Radio and RadioButton
isRadioButtonGroup: false // Used internally by RadioButton
}
},
watch: {
/**
* Set checked state on the correct children Radio
* or RadioButton when v-model change.
*/
value() {
this.findChecked()
this.initChecked()
}
},
methods: {
/**
* This is called from a child Radio or RadioButton.
* Emit input event to update the user v-model.
*/
updateValue(value, event) {
this.$emit('change', value, event)
this.$emit('input', value)
},
findChecked() {
/**
* Set checked state on the correct children Radio or RadioButton based on v-model.
*/
initChecked() {
this.$children.forEach((child) => {
child.size = this.buttonSize
this.isRadioButtonGroup = child.isRadioButton
this.isRadioButtonGroup = child.isRadioButtonComponent
child.isChecked = this.value === child.value
})
}
},
mounted() {
this.findChecked()
this.initChecked()
}
}
</script>
14 changes: 8 additions & 6 deletions src/components/switch/Switch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,23 @@
},
data() {
return {
newValue: this.value
newValue: this.value || this.checked
}
},
watch: {
/**
* When v-model change, set internal value.
*/
value(value) {
this.newValue = value
},
/**
* Emit input event to update the user v-model.
*/
newValue(value) {
this.$emit('input', value)
}
},
mounted() {
if (this.checked) {
this.newValue = this.checked
}
}
}
</script>

0 comments on commit 38a0ac8

Please sign in to comment.