This repository was archived by the owner on Nov 30, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +21
-13
lines changed Expand file tree Collapse file tree 1 file changed +21
-13
lines changed Original file line number Diff line number Diff line change @@ -70,7 +70,8 @@ export default {
70
70
data () {
71
71
return {
72
72
mdcTextField: undefined ,
73
- mdcRipple: undefined
73
+ mdcRipple: undefined ,
74
+ slotObserver: undefined
74
75
}
75
76
},
76
77
computed: {
@@ -90,28 +91,35 @@ export default {
90
91
}
91
92
},
92
93
mounted () {
93
- if (this .$slots .leadingIcon ) {
94
- this .$slots .leadingIcon .map (n => {
95
- n .elm .classList .add (' mdc-text-field__icon' )
96
- })
97
- }
98
-
99
- if (this .$slots .trailingIcon ) {
100
- this .$slots .trailingIcon .map (n => {
101
- n .elm .classList .add (' mdc-text-field__icon' )
102
- })
103
- }
104
-
94
+ this .updateSlots ()
95
+ this .slotObserver = new MutationObserver ( () => this .updateSlots ())
96
+ this .slotObserver .observe (this .$el , {
97
+ childList: true ,
98
+ subtree: true
99
+ })
105
100
this .mdcTextField = MDCTextField .attachTo (this .$el )
106
101
},
107
102
beforeDestroy () {
103
+ this .slotObserver .disconnect ()
108
104
this .mdcTextField .destroy ()
109
105
110
106
if (typeof this .mdcRipple !== ' undefined' ) {
111
107
this .mdcRipple .destroy ()
112
108
}
113
109
},
114
110
methods: {
111
+ updateSlots () {
112
+ if (this .$slots .leadingIcon ) {
113
+ this .$slots .leadingIcon .map (n => {
114
+ n .elm .classList .add (' mdc-text-field__icon' )
115
+ })
116
+ }
117
+ if (this .$slots .trailingIcon ) {
118
+ this .$slots .trailingIcon .map (n => {
119
+ n .elm .classList .add (' mdc-text-field__icon' )
120
+ })
121
+ }
122
+ },
115
123
onInput (event ) {
116
124
debounce (this .$emit (' input' , event .target .value ))
117
125
}
You can’t perform that action at this time.
0 commit comments