Skip to content

Commit 9e77ab8

Browse files
committed
- BsTextArea: fixed bug could not determine its height when auto-grow and readonly were enabled and the model-value wasn't empty.
- Update CHANGELOG.md - Bump to version v2.17
1 parent c345117 commit 9e77ab8

File tree

6 files changed

+64
-22
lines changed

6 files changed

+64
-22
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
> All notable changes to this project will be documented in this file.
44
55

6+
## v2.1.7
7+
8+
Released: February 03, 2025
9+
10+
### Bug Fixes
11+
12+
- **BsTextArea**: fixed bug could not determine its height when `auto-grow` and `readonly`
13+
were enabled and the `model-value` wasn't empty.
14+
15+
616
## v2.1.6
717

818
Released: February 01, 2025

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-mdbootstrap",
3-
"version": "2.1.6",
3+
"version": "2.1.7",
44
"description": "Bootstrap5 Material Design Components for Vue.js",
55
"author": {
66
"name": "Ahmad Fajar",

scss/banner.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* Vue MDBootstrap v2.1.6
2+
* Vue MDBootstrap v2.1.7
33
* Released under the BSD-3 License.
44
* Copyright Ahmad Fajar (https://ahmadfajar.github.io).
55
*/

src/components/Field/BsTextArea.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { cssPrefix } from '@/mixins/CommonApi';
1111
import { booleanProp, stringProp, validStringOrNumberProp } from '@/mixins/CommonProps';
1212
import type { TBsTextArea, TRecord, TTextAreaOptionProps } from '@/types';
1313
import Helper from '@/utils/Helper';
14-
import { computed, defineComponent, ref, watch } from 'vue';
14+
import { computed, defineComponent, ref, watch, watchEffect } from 'vue';
1515

1616
export default defineComponent<TBsTextArea>({
1717
name: 'BsTextArea',
@@ -63,10 +63,11 @@ export default defineComponent<TBsTextArea>({
6363
thisProps.autocomplete && Helper.isString(thisProps.autocomplete)
6464
? thisProps.autocomplete
6565
: thisProps.autocomplete
66-
? 'on'
67-
: Helper.uuid();
66+
? 'on'
67+
: Helper.uuid();
6868
const localValue = ref<string | number | undefined | null>(thisProps.modelValue);
6969
const rowHeight = ref<string | number | undefined | null>(thisProps.rowHeight);
70+
const inputRef = ref<HTMLTextAreaElement>();
7071
const isFocused = ref(false);
7172
const validator = useGetValidationResult(thisProps, isFocused);
7273
const showClearButton = computed<boolean>(() => useShowClearButton(thisProps, localValue));
@@ -97,12 +98,19 @@ export default defineComponent<TBsTextArea>({
9798
thisProps.noResize || (thisProps.autoGrow && !thisProps.noResize),
9899
}));
99100

100-
watch(
101-
() => thisProps.modelValue,
102-
(value) => {
103-
localValue.value = value;
101+
watchEffect(() => {
102+
localValue.value = thisProps.modelValue;
103+
if (thisProps.autoGrow && !thisProps.noResize && inputRef.value) {
104+
inputRef.value.parentElement &&
105+
(inputRef.value.parentElement.dataset.clone = localValue.value as string);
104106
}
105-
);
107+
});
108+
// watch(
109+
// () => thisProps.modelValue,
110+
// (value) => {
111+
// localValue.value = value;
112+
// }
113+
// );
106114

107115
return () =>
108116
useRenderTextArea(
@@ -111,6 +119,7 @@ export default defineComponent<TBsTextArea>({
111119
thisProps,
112120
wrapperClasses,
113121
controlClasses,
122+
inputRef,
114123
localValue,
115124
rowHeight,
116125
isFocused,

src/components/Field/field.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,9 +637,26 @@
637637
&.#{vars.$prefix}textarea-autogrow {
638638
> .#{vars.$prefix}field-inner {
639639
> .#{vars.$prefix}field-activator {
640+
align-items: normal;
641+
display: grid;
642+
643+
&::after {
644+
content: attr(data-clone) " ";
645+
font: inherit;
646+
white-space: pre-wrap;
647+
visibility: hidden;
648+
}
649+
640650
> textarea {
641651
overflow-y: hidden;
642652
}
653+
654+
> textarea,
655+
&::after {
656+
margin: var(--#{vars.$prefix}field-padding-top) 0 0 0;
657+
padding: 0 var(--#{vars.$prefix}field-padding-end) var(--#{vars.$prefix}field-padding-bottom) var(--#{vars.$prefix}field-padding-start);
658+
grid-area: 1 / 1 / 2 / 2;
659+
}
643660
}
644661
}
645662
}

src/components/Field/mixins/textFieldApi.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,12 @@ export function useCreateValidationIcon(
275275
size: iconSize as Prop<number | undefined>,
276276
})
277277
: hasValidated && !hasError
278-
? h<TBsIcon>(BsIcon, {
279-
class: 'icon-success text-success',
280-
icon: `check_${iconVariant}` as Prop<string>,
281-
size: iconSize as Prop<number | undefined>,
282-
})
283-
: undefined,
278+
? h<TBsIcon>(BsIcon, {
279+
class: 'icon-success text-success',
280+
icon: `check_${iconVariant}` as Prop<string>,
281+
size: iconSize as Prop<number | undefined>,
282+
})
283+
: undefined,
284284
])
285285
: createCommentVNode(' v-if-validation-icon ')
286286
);
@@ -452,6 +452,7 @@ export function useRenderTextField(
452452
function createTextAreaInputField(
453453
props: Readonly<TTextAreaOptionProps>,
454454
emit: TEmitFn,
455+
inputRef: Ref<HTMLTextAreaElement | undefined>,
455456
localValue: Ref<string | number | undefined | null>,
456457
rowHeight: Ref<string | number | undefined | null>,
457458
isFocused: Ref<boolean>,
@@ -463,6 +464,7 @@ function createTextAreaInputField(
463464
h('textarea', {
464465
...useMakeInputBaseAttrs(props),
465466
...useInputTextFieldAttrs(props, autocomplete),
467+
ref: inputRef,
466468
role: 'textbox',
467469
rows: canGrow ? 2 : props.rows && !props.rowHeight ? props.rows : undefined,
468470
style: rowHeight.value && {
@@ -475,12 +477,14 @@ function createTextAreaInputField(
475477
onKeydown: (e: KeyboardEvent) => emit('keydown', e),
476478
onInput: (e: InputEvent): void => {
477479
if (canGrow) {
478-
const target = e.target as HTMLElement;
479-
target.style.height = 'auto';
480-
nextTick().then(() => {
481-
rowHeight.value = Helper.cssUnit(target.scrollHeight);
482-
target.style.height = Helper.cssUnit(target.scrollHeight) || 'auto';
483-
});
480+
const target = e.target as HTMLTextAreaElement;
481+
target.parentElement &&
482+
(target.parentElement.dataset.clone = target.value as string);
483+
// target.style.height = 'auto';
484+
// nextTick().then(() => {
485+
// rowHeight.value = Helper.cssUnit(target.scrollHeight);
486+
// target.style.height = Helper.cssUnit(target.scrollHeight) || 'auto';
487+
// });
484488
}
485489
},
486490
}),
@@ -494,6 +498,7 @@ export function useRenderTextArea(
494498
props: Readonly<TTextAreaOptionProps>,
495499
wrapperCss: ComputedRef<TRecord>,
496500
controlCss: ComputedRef<TRecord>,
501+
inputRef: Ref<HTMLTextAreaElement | undefined>,
497502
localValue: Ref<string | number | undefined | null>,
498503
rowHeight: Ref<string | number | undefined | null>,
499504
isFocused: Ref<boolean>,
@@ -524,6 +529,7 @@ export function useRenderTextArea(
524529
createTextAreaInputField(
525530
props,
526531
emit,
532+
inputRef,
527533
localValue,
528534
rowHeight,
529535
isFocused,

0 commit comments

Comments
 (0)