Skip to content

Commit 6594fe3

Browse files
committed
fix: textarea
1 parent 82f28ce commit 6594fe3

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

components/_util/BaseInput.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { computed, defineComponent, shallowRef, ref, watch } from 'vue';
33
import PropTypes from './vue-types';
44
import type { BaseInputInnerExpose } from './BaseInputInner';
55
import BaseInputInner from './BaseInputInner';
6+
import { styleObjectToString } from '../vc-util/Dom/css';
67

78
export interface BaseInputExpose {
89
focus: () => void;
@@ -32,7 +33,7 @@ const BaseInput = defineComponent({
3233
default: 'input',
3334
},
3435
size: PropTypes.string,
35-
style: PropTypes.style,
36+
style: PropTypes.oneOfType([String, Object]),
3637
class: PropTypes.string,
3738
},
3839
emits: [
@@ -134,13 +135,18 @@ const BaseInput = defineComponent({
134135
const handlePaste = (e: ClipboardEvent) => {
135136
emit('paste', e);
136137
};
138+
const styleString = computed(() => {
139+
return props.style && typeof props.style !== 'string'
140+
? styleObjectToString(props.style)
141+
: props.style;
142+
});
137143
return () => {
138-
const { tag: Tag, style, ...restProps } = props;
144+
const { style, lazy, ...restProps } = props;
139145
return (
140146
<BaseInputInner
141147
{...restProps}
142148
{...attrs}
143-
style={JSON.stringify(style)}
149+
style={styleString.value}
144150
onInput={handleInput}
145151
onChange={handleChange}
146152
onBlur={handleBlur}

components/typography/util.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { CSSProperties, VNodeTypes } from 'vue';
22
import { createApp } from 'vue';
3+
import { styleToString } from '../vc-util/Dom/css';
34

45
interface MeasureResult {
56
finished: boolean;
@@ -23,13 +24,6 @@ const wrapperStyle: CSSProperties = {
2324
lineHeight: 'inherit',
2425
};
2526

26-
function styleToString(style: CSSStyleDeclaration) {
27-
// There are some different behavior between Firefox & Chrome.
28-
// We have to handle this ourself.
29-
const styleNames = Array.prototype.slice.apply(style);
30-
return styleNames.map(name => `${name}: ${style.getPropertyValue(name)};`).join('');
31-
}
32-
3327
function resetDomStyles(target: HTMLElement, origin: HTMLElement) {
3428
target.setAttribute('aria-hidden', 'true');
3529
const originStyle = window.getComputedStyle(origin);

components/vc-util/Dom/css.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,16 @@ export function getOffset(node: any) {
112112
(docElem.clientTop || document.body.clientTop || 0),
113113
};
114114
}
115+
116+
export function styleToString(style: CSSStyleDeclaration) {
117+
// There are some different behavior between Firefox & Chrome.
118+
// We have to handle this ourself.
119+
const styleNames = Array.prototype.slice.apply(style);
120+
return styleNames.map(name => `${name}: ${style.getPropertyValue(name)};`).join('');
121+
}
122+
123+
export function styleObjectToString(style: Record<string, string>) {
124+
return Object.keys(style)
125+
.map(name => `${name}: ${style[name]};`)
126+
.join('');
127+
}

0 commit comments

Comments
 (0)