Skip to content

Commit de8a6ae

Browse files
committed
Implement "important" prop handling
1 parent 9abfd21 commit de8a6ae

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

src/components/TextareaAutosize.vue

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export default {
2323
*/
2424
value: {
2525
type: [String, Number],
26-
required: false,
2726
default: ''
2827
},
2928
@@ -32,7 +31,6 @@ export default {
3231
*/
3332
autosize: {
3433
type: Boolean,
35-
required: false,
3634
default: true
3735
},
3836
@@ -41,7 +39,6 @@ export default {
4139
*/
4240
minHeight: {
4341
type: [Number],
44-
required: false,
4542
'default': null
4643
},
4744
@@ -50,8 +47,15 @@ export default {
5047
*/
5148
maxHeight: {
5249
type: [Number],
53-
required: false,
5450
'default': null
51+
},
52+
53+
/*
54+
* Force !important for style properties
55+
*/
56+
important: {
57+
type: [Boolean, Array],
58+
default: false
5559
}
5660
},
5761
@@ -71,13 +75,28 @@ export default {
7175
let objStyles = {}
7276
7377
if (this.autosize) {
74-
objStyles.resize = 'none'
78+
objStyles.resize = !this.isResizeImportant ? 'none' : 'none !important'
7579
if (!this.maxHeightScroll) {
76-
objStyles.overflow = 'hidden'
80+
objStyles.overflow = !this.isOverflowImportant ? 'hidden' : 'hidden !important'
7781
}
7882
}
7983
8084
return objStyles
85+
},
86+
87+
isResizeImportant () {
88+
const imp = this.important
89+
return imp === true || (Array.isArray(imp) && imp.includes('resize'))
90+
},
91+
92+
isOverflowImportant () {
93+
const imp = this.important
94+
return imp === true || (Array.isArray(imp) && imp.includes('overflow'))
95+
},
96+
97+
isHeightImportant () {
98+
const imp = this.important
99+
return imp === true || (Array.isArray(imp) && imp.includes('height'))
81100
}
82101
},
83102
@@ -93,7 +112,10 @@ export default {
93112
* Auto resize textarea by height
94113
*/
95114
resize: function () {
96-
this.$el.style.height = 'auto'
115+
const important = this.isHeightImportant ? 'important' : undefined
116+
117+
this.$el.style.setProperty('height', 'auto', important)
118+
97119
let contentHeight = this.$el.scrollHeight + 1
98120
99121
if (this.minHeight) {
@@ -109,7 +131,8 @@ export default {
109131
}
110132
}
111133
112-
this.$el.style.height = contentHeight + 'px'
134+
const heightVal = contentHeight + 'px'
135+
this.$el.style.setProperty('height', heightVal, important)
113136
return this
114137
}
115138
},

0 commit comments

Comments
 (0)