16
16
<div class =" mdc-checkbox__mixedmark" ></div >
17
17
</div >
18
18
</div >
19
- <div ref =" label" >
20
- <label :for =" _uid" v-if =" label" >{{ label }}</label >
21
- </div >
19
+ <label ref =" label" :for =" _uid"
20
+ ><slot >{{label}}</slot ></label >
22
21
</div >
23
22
</template >
24
23
25
24
<script >
26
25
27
26
/* global HTMLElement */
28
27
import MDCCheckboxFoundation from ' @material/checkbox/foundation'
28
+ import MDCFormFieldFoundation from ' @material/form-field/foundation'
29
29
import {getCorrectEventName } from ' @material/animation'
30
30
import {DispatchFocusMixin } from ' ../base'
31
31
import {RippleBase } from ' ../ripple'
@@ -52,10 +52,13 @@ export default {
52
52
}
53
53
},
54
54
computed: {
55
+ hasLabel () {
56
+ return this .label || this .$slots .default
57
+ },
55
58
formFieldClasses () {
56
59
return {
57
- ' mdc-form-field' : this .label ,
58
- ' mdc-form-field--align-end' : this .label && this .alignEnd
60
+ ' mdc-form-field' : this .hasLabel ,
61
+ ' mdc-form-field--align-end' : this .hasLabel && this .alignEnd
59
62
}
60
63
}
61
64
},
@@ -83,28 +86,21 @@ export default {
83
86
registerChangeHandler : (handler ) => this .$refs .control .addEventListener (' change' , handler),
84
87
deregisterChangeHandler : (handler ) => this .$refs .control .removeEventListener (' change' , handler),
85
88
getNativeControl : () => this .$refs .control ,
86
- forceLayout : () => this .$forceUpdate () ,
89
+ forceLayout : () => this .$refs . root . offsetWidth ,
87
90
isAttachedToDOM : () => Boolean (this .$el .parentNode )
88
91
})
89
92
90
- this .foundation .init ()
91
- this .foundation .setChecked (this .checked )
92
- this .foundation .setDisabled (this .disabled )
93
- this .foundation .setIndeterminate (this .indeterminate )
94
-
95
93
this .ripple = new RippleBase (this , {
96
94
isUnbounded : () => true ,
97
95
isSurfaceActive : () => RippleBase .isSurfaceActive (this .$refs .control ),
98
96
registerInteractionHandler : (evt , handler ) => {
99
- this .$refs .root .addEventListener (evt, handler)
100
- this .$refs .label .addEventListener (evt, handler)
97
+ this .$refs .control .addEventListener (evt, handler)
101
98
},
102
99
deregisterInteractionHandler : (evt , handler ) => {
103
- this .$refs .root .removeEventListener (evt, handler)
104
- this .$refs .label .removeEventListener (evt, handler)
100
+ this .$refs .control .addEventListener (evt, handler)
105
101
},
106
102
computeBoundingRect : () => {
107
- const {left , top } = this .$refs .control .getBoundingClientRect ()
103
+ const {left , top } = this .$refs .root .getBoundingClientRect ()
108
104
const DIM = 40
109
105
return {
110
106
top,
@@ -116,9 +112,32 @@ export default {
116
112
}
117
113
}
118
114
})
115
+
116
+ this .formField = new MDCFormFieldFoundation ({
117
+ registerInteractionHandler : (type , handler ) => {
118
+ this .$refs .label .addEventListener (type, handler)
119
+ },
120
+ deregisterInteractionHandler : (type , handler ) => {
121
+ this .$refs .label .removeEventListener (type, handler)
122
+ },
123
+ activateInputRipple : () => {
124
+ this .ripple && this .ripple .activate ()
125
+ },
126
+ deactivateInputRipple : () => {
127
+ this .ripple && this .ripple .deactivate ()
128
+ },
129
+ });
130
+
131
+ this .foundation .init ()
119
132
this .ripple .init ()
133
+ this .formField .init ()
134
+ this .foundation .setChecked (this .checked )
135
+ this .foundation .setDisabled (this .disabled )
136
+ this .foundation .setIndeterminate (this .indeterminate )
137
+
120
138
},
121
139
beforeDestroy () {
140
+ this .formField .destroy ()
122
141
this .ripple .destroy ()
123
142
this .foundation .destroy ()
124
143
},
0 commit comments