@@ -15,11 +15,14 @@ export interface UseTextareaAutosizeOptions {
15
15
onResize ?: ( ) => void
16
16
/** Specify style target to apply the height based on textarea content. If not provided it will use textarea it self. */
17
17
styleTarget ?: MaybeRef < HTMLElement >
18
+ /** Specify the style property that will be used to manipulate height. Can be `height | minHeight`. Default value is `height`. */
19
+ styleProp ?: 'height' | 'minHeight'
18
20
}
19
21
20
22
export function useTextareaAutosize ( options ?: UseTextareaAutosizeOptions ) {
21
23
const textarea = ref < HTMLTextAreaElement > ( options ?. element as any )
22
24
const input = ref < string > ( options ?. input as any )
25
+ const styleProp = options ?. styleProp ?? 'height'
23
26
const textareaScrollHeight = ref ( 1 )
24
27
25
28
function triggerResize ( ) {
@@ -28,17 +31,17 @@ export function useTextareaAutosize(options?: UseTextareaAutosizeOptions) {
28
31
29
32
let height = ''
30
33
31
- textarea . value ! . style . height = '1px'
34
+ textarea . value . style [ styleProp ] = '1px'
32
35
textareaScrollHeight . value = textarea . value ?. scrollHeight
33
36
34
37
// If style target is provided update its height
35
38
if ( options ?. styleTarget )
36
- toValue ( options . styleTarget ) . style . height = `${ textareaScrollHeight . value } px`
39
+ toValue ( options . styleTarget ) . style [ styleProp ] = `${ textareaScrollHeight . value } px`
37
40
// else update textarea's height by updating height variable
38
41
else
39
42
height = `${ textareaScrollHeight . value } px`
40
43
41
- textarea . value ! . style . height = height
44
+ textarea . value . style [ styleProp ] = height
42
45
43
46
options ?. onResize ?.( )
44
47
}
0 commit comments