Skip to content

Commit

Permalink
fix: textarea
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjinzhou committed Jun 4, 2024
1 parent 82f28ce commit 6594fe3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
12 changes: 9 additions & 3 deletions components/_util/BaseInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { computed, defineComponent, shallowRef, ref, watch } from 'vue';
import PropTypes from './vue-types';
import type { BaseInputInnerExpose } from './BaseInputInner';
import BaseInputInner from './BaseInputInner';
import { styleObjectToString } from '../vc-util/Dom/css';

export interface BaseInputExpose {
focus: () => void;
Expand Down Expand Up @@ -32,7 +33,7 @@ const BaseInput = defineComponent({
default: 'input',
},
size: PropTypes.string,
style: PropTypes.style,
style: PropTypes.oneOfType([String, Object]),
class: PropTypes.string,
},
emits: [
Expand Down Expand Up @@ -134,13 +135,18 @@ const BaseInput = defineComponent({
const handlePaste = (e: ClipboardEvent) => {
emit('paste', e);
};
const styleString = computed(() => {
return props.style && typeof props.style !== 'string'
? styleObjectToString(props.style)
: props.style;
});
return () => {
const { tag: Tag, style, ...restProps } = props;
const { style, lazy, ...restProps } = props;
return (
<BaseInputInner
{...restProps}
{...attrs}
style={JSON.stringify(style)}
style={styleString.value}
onInput={handleInput}
onChange={handleChange}
onBlur={handleBlur}
Expand Down
8 changes: 1 addition & 7 deletions components/typography/util.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { CSSProperties, VNodeTypes } from 'vue';
import { createApp } from 'vue';
import { styleToString } from '../vc-util/Dom/css';

interface MeasureResult {
finished: boolean;
Expand All @@ -23,13 +24,6 @@ const wrapperStyle: CSSProperties = {
lineHeight: 'inherit',
};

function styleToString(style: CSSStyleDeclaration) {
// There are some different behavior between Firefox & Chrome.
// We have to handle this ourself.
const styleNames = Array.prototype.slice.apply(style);
return styleNames.map(name => `${name}: ${style.getPropertyValue(name)};`).join('');
}

function resetDomStyles(target: HTMLElement, origin: HTMLElement) {
target.setAttribute('aria-hidden', 'true');
const originStyle = window.getComputedStyle(origin);
Expand Down
13 changes: 13 additions & 0 deletions components/vc-util/Dom/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,16 @@ export function getOffset(node: any) {
(docElem.clientTop || document.body.clientTop || 0),
};
}

export function styleToString(style: CSSStyleDeclaration) {
// There are some different behavior between Firefox & Chrome.
// We have to handle this ourself.
const styleNames = Array.prototype.slice.apply(style);
return styleNames.map(name => `${name}: ${style.getPropertyValue(name)};`).join('');
}

export function styleObjectToString(style: Record<string, string>) {
return Object.keys(style)
.map(name => `${name}: ${style[name]};`)
.join('');
}

0 comments on commit 6594fe3

Please sign in to comment.