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

Commit 2fe244f

Browse files
tychenjiajunmatsp
authored andcommitted
fix(checkbox): lack of disabled prop (#251)
1 parent a475f3a commit 2fe244f

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

components/checkbox/Checkbox.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ export default {
4141
indeterminate: {
4242
type: Boolean,
4343
default: false
44+
},
45+
disabled: {
46+
type: Boolean,
47+
default: false
4448
}
4549
},
4650
data () {
@@ -69,11 +73,15 @@ export default {
6973
if (this.model && value) {
7074
this.model = false
7175
}
76+
},
77+
disabled (value) {
78+
this.mdcCheckbox.disabled = true
7279
}
7380
},
7481
mounted () {
7582
this.mdcCheckbox = MDCCheckbox.attachTo(this.$el)
7683
this.mdcCheckbox.indeterminate = this.indeterminate
84+
this.mdcCheckbox.disabled = this.disabled
7785
},
7886
beforeDestroy () {
7987
this.mdcCheckbox.destroy()
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import 'mutationobserver-shim'
2+
import { mount } from '@vue/test-utils'
3+
import Checkbox from '../Checkbox.vue'
4+
5+
describe('Checkbox', () => {
6+
it('should mount', () => {
7+
let wrapper = mount(Checkbox)
8+
expect(wrapper.isVueInstance()).toBeTruthy()
9+
expect(wrapper.vm.$data.mdcCheckbox).toBeDefined()
10+
})
11+
12+
it('should render with no prop', () => {
13+
let wrapper = mount(Checkbox)
14+
expect(wrapper).toMatchSnapshot()
15+
expect(wrapper.classes()).toContain('mdc-checkbox')
16+
expect(wrapper.find('input').attributes('disabled')).toBeUndefined()
17+
})
18+
19+
it('should render as disabled', () => {
20+
let wrapper = mount(Checkbox, {
21+
propsData: {
22+
disabled: true
23+
}
24+
})
25+
expect(wrapper).toMatchSnapshot()
26+
expect(wrapper.classes()).toContain('mdc-checkbox--disabled')
27+
expect(wrapper.find('input').attributes('disabled')).toBeDefined()
28+
})
29+
30+
it('should render as indeterminate', () => {
31+
let wrapper = mount(Checkbox, {
32+
propsData: {
33+
indeterminate: true
34+
}
35+
})
36+
expect(wrapper).toMatchSnapshot()
37+
expect(wrapper.vm.$data.mdcCheckbox.indeterminate).toBeTruthy()
38+
expect(wrapper.find('input').element.checked).toBeFalsy()
39+
expect(wrapper.find('input').element.indeterminate).toBeTruthy()
40+
})
41+
42+
it('should render as checked', () => {
43+
let wrapper = mount(Checkbox, {
44+
propsData: {
45+
checked: true
46+
}
47+
})
48+
expect(wrapper).toMatchSnapshot()
49+
expect(wrapper.vm.$data.mdcCheckbox.checked).toBeTruthy()
50+
expect(wrapper.find('input').element.checked).toBeTruthy()
51+
})
52+
53+
it('should render and emit', () => {
54+
let wrapper = mount(Checkbox)
55+
56+
const input = wrapper.find('input')
57+
58+
input.setChecked()
59+
expect(wrapper.emitted().change).toBeTruthy()
60+
expect(wrapper.emitted().change.length).toBe(1)
61+
expect(wrapper.emitted().change[0]).toEqual([true])
62+
expect(wrapper.vm.$data.mdcCheckbox.checked).toBeTruthy()
63+
expect(wrapper.find('input').element.checked).toBeTruthy()
64+
65+
input.setChecked(false)
66+
expect(wrapper.emitted().change).toBeTruthy()
67+
expect(wrapper.emitted().change.length).toBe(2)
68+
expect(wrapper.emitted().change[1]).toEqual([false])
69+
expect(wrapper.vm.$data.mdcCheckbox.checked).toBeFalsy()
70+
expect(wrapper.find('input').element.checked).toBeFalsy()
71+
})
72+
})
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Checkbox should render as checked 1`] = `
4+
<div class="mdc-checkbox mdc-checkbox--upgraded"><input type="checkbox" class="mdc-checkbox__native-control">
5+
<div class="mdc-checkbox__background"><svg viewBox="0 0 24 24" class="mdc-checkbox__checkmark">
6+
<path fill="none" stroke="white" d="M1.73,12.91 8.1,19.28 22.79,4.59" class="mdc-checkbox__checkmark-path"></path>
7+
</svg>
8+
<div class="mdc-checkbox__mixedmark"></div>
9+
</div>
10+
</div>
11+
`;
12+
13+
exports[`Checkbox should render as disabled 1`] = `
14+
<div class="mdc-checkbox mdc-checkbox--upgraded mdc-checkbox--disabled"><input type="checkbox" class="mdc-checkbox__native-control" disabled="">
15+
<div class="mdc-checkbox__background"><svg viewBox="0 0 24 24" class="mdc-checkbox__checkmark">
16+
<path fill="none" stroke="white" d="M1.73,12.91 8.1,19.28 22.79,4.59" class="mdc-checkbox__checkmark-path"></path>
17+
</svg>
18+
<div class="mdc-checkbox__mixedmark"></div>
19+
</div>
20+
</div>
21+
`;
22+
23+
exports[`Checkbox should render as indeterminate 1`] = `
24+
<div class="mdc-checkbox mdc-checkbox--upgraded mdc-checkbox--selected"><input type="checkbox" class="mdc-checkbox__native-control" aria-checked="mixed">
25+
<div class="mdc-checkbox__background"><svg viewBox="0 0 24 24" class="mdc-checkbox__checkmark">
26+
<path fill="none" stroke="white" d="M1.73,12.91 8.1,19.28 22.79,4.59" class="mdc-checkbox__checkmark-path"></path>
27+
</svg>
28+
<div class="mdc-checkbox__mixedmark"></div>
29+
</div>
30+
</div>
31+
`;
32+
33+
exports[`Checkbox should render with no prop 1`] = `
34+
<div class="mdc-checkbox mdc-checkbox--upgraded"><input type="checkbox" class="mdc-checkbox__native-control">
35+
<div class="mdc-checkbox__background"><svg viewBox="0 0 24 24" class="mdc-checkbox__checkmark">
36+
<path fill="none" stroke="white" d="M1.73,12.91 8.1,19.28 22.79,4.59" class="mdc-checkbox__checkmark-path"></path>
37+
</svg>
38+
<div class="mdc-checkbox__mixedmark"></div>
39+
</div>
40+
</div>
41+
`;

0 commit comments

Comments
 (0)