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 PropTypes from './vue-types';
import type { BaseInputInnerExpose } from './BaseInputInner'; import type { BaseInputInnerExpose } from './BaseInputInner';
import BaseInputInner from './BaseInputInner'; import BaseInputInner from './BaseInputInner';
import { styleObjectToString } from '../vc-util/Dom/css';
export interface BaseInputExpose { export interface BaseInputExpose {
focus: () => void; focus: () => void;
@ -32,7 +33,7 @@ const BaseInput = defineComponent({
default: 'input', default: 'input',
}, },
size: PropTypes.string, size: PropTypes.string,
style: PropTypes.style, style: PropTypes.oneOfType([String, Object]),
class: PropTypes.string, class: PropTypes.string,
}, },
emits: [ emits: [
@ -134,13 +135,18 @@ const BaseInput = defineComponent({
const handlePaste = (e: ClipboardEvent) => { const handlePaste = (e: ClipboardEvent) => {
emit('paste', e); emit('paste', e);
}; };
const styleString = computed(() => {
return props.style && typeof props.style !== 'string'
? styleObjectToString(props.style)
: props.style;
});
return () => { return () => {
const { tag: Tag, style, ...restProps } = props; const { style, lazy, ...restProps } = props;
return ( return (
<BaseInputInner <BaseInputInner
{...restProps} {...restProps}
{...attrs} {...attrs}
style={JSON.stringify(style)} style={styleString.value}
onInput={handleInput} onInput={handleInput}
onChange={handleChange} onChange={handleChange}
onBlur={handleBlur} onBlur={handleBlur}

8
components/typography/util.tsx

@ -1,5 +1,6 @@
import type { CSSProperties, VNodeTypes } from 'vue'; import type { CSSProperties, VNodeTypes } from 'vue';
import { createApp } from 'vue'; import { createApp } from 'vue';
import { styleToString } from '../vc-util/Dom/css';
interface MeasureResult { interface MeasureResult {
finished: boolean; finished: boolean;
@ -23,13 +24,6 @@ const wrapperStyle: CSSProperties = {
lineHeight: 'inherit', 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) { function resetDomStyles(target: HTMLElement, origin: HTMLElement) {
target.setAttribute('aria-hidden', 'true'); target.setAttribute('aria-hidden', 'true');
const originStyle = window.getComputedStyle(origin); 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), (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