1616 <div class =" mdc-checkbox__mixedmark" ></div >
1717 </div >
1818 </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 >
2221 </div >
2322</template >
2423
2524<script >
2625
2726/* global HTMLElement */
2827import MDCCheckboxFoundation from ' @material/checkbox/foundation'
28+ import MDCFormFieldFoundation from ' @material/form-field/foundation'
2929import {getCorrectEventName } from ' @material/animation'
3030import {DispatchFocusMixin } from ' ../base'
3131import {RippleBase } from ' ../ripple'
@@ -52,10 +52,13 @@ export default {
5252 }
5353 },
5454 computed: {
55+ hasLabel () {
56+ return this .label || this .$slots .default
57+ },
5558 formFieldClasses () {
5659 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
5962 }
6063 }
6164 },
@@ -83,28 +86,21 @@ export default {
8386 registerChangeHandler : (handler ) => this .$refs .control .addEventListener (' change' , handler),
8487 deregisterChangeHandler : (handler ) => this .$refs .control .removeEventListener (' change' , handler),
8588 getNativeControl : () => this .$refs .control ,
86- forceLayout : () => this .$forceUpdate () ,
89+ forceLayout : () => this .$refs . root . offsetWidth ,
8790 isAttachedToDOM : () => Boolean (this .$el .parentNode )
8891 })
8992
90- this .foundation .init ()
91- this .foundation .setChecked (this .checked )
92- this .foundation .setDisabled (this .disabled )
93- this .foundation .setIndeterminate (this .indeterminate )
94-
9593 this .ripple = new RippleBase (this , {
9694 isUnbounded : () => true ,
9795 isSurfaceActive : () => RippleBase .isSurfaceActive (this .$refs .control ),
9896 registerInteractionHandler : (evt , handler ) => {
99- this .$refs .root .addEventListener (evt, handler)
100- this .$refs .label .addEventListener (evt, handler)
97+ this .$refs .control .addEventListener (evt, handler)
10198 },
10299 deregisterInteractionHandler : (evt , handler ) => {
103- this .$refs .root .removeEventListener (evt, handler)
104- this .$refs .label .removeEventListener (evt, handler)
100+ this .$refs .control .addEventListener (evt, handler)
105101 },
106102 computeBoundingRect : () => {
107- const {left , top } = this .$refs .control .getBoundingClientRect ()
103+ const {left , top } = this .$refs .root .getBoundingClientRect ()
108104 const DIM = 40
109105 return {
110106 top,
@@ -116,9 +112,32 @@ export default {
116112 }
117113 }
118114 })
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 ()
119132 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+
120138 },
121139 beforeDestroy () {
140+ this .formField .destroy ()
122141 this .ripple .destroy ()
123142 this .foundation .destroy ()
124143 },
0 commit comments