Browse Source

fix: textarea

pull/7632/head
tangjinzhou 6 months ago
parent
commit
6594fe3964
  1. 12
      components/_util/BaseInput.tsx
  2. 8
      components/typography/util.tsx
  3. 13
      components/vc-util/Dom/css.ts

12
components/_util/BaseInput.tsx

@ -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;
@ -32,7 +33,7 @@ const BaseInput = defineComponent({
default: 'input',
},
size: PropTypes.string,
style: PropTypes.style,
style: PropTypes.oneOfType([String, Object]),
class: PropTypes.string,
},
emits: [
@ -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}

8
components/typography/util.tsx

@ -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;
@ -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);

13
components/vc-util/Dom/css.ts

@ -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('');
}

Loading…
Cancel
Save