From 197e209b4e132fca8b13f56ae1f1fe7895536a30 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Sun, 12 Feb 2023 10:05:44 +0800 Subject: [PATCH] fix: typography #6244 --- components/typography/Base.tsx | 9 ++++++--- components/typography/Title.tsx | 4 ++-- components/typography/index.en-US.md | 2 +- components/typography/index.zh-CN.md | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/components/typography/Base.tsx b/components/typography/Base.tsx index e0d55db8b..6e9808e0a 100644 --- a/components/typography/Base.tsx +++ b/components/typography/Base.tsx @@ -31,6 +31,7 @@ import type { EventHandler } from '../_util/EventInterface'; import omit from '../_util/omit'; import type { AutoSizeType } from '../input/inputProps'; import useMergedState from '../_util/hooks/useMergedState'; +import { findDOMNode } from '../_util/props-util'; export type BaseType = 'secondary' | 'success' | 'warning' | 'danger'; @@ -198,7 +199,9 @@ const Base = defineComponent({ }); function getChildrenText(): string { - return props.ellipsis || props.editable ? props.content : contentRef.value?.$el?.innerText; + return props.ellipsis || props.editable + ? props.content + : findDOMNode(contentRef.value)?.innerText; } // =============== Expand =============== @@ -324,7 +327,7 @@ const Base = defineComponent({ if ( !rows || rows < 0 || - !contentRef.value?.$el || + !findDOMNode(contentRef.value) || state.expanded || props.content === undefined ) @@ -338,7 +341,7 @@ const Base = defineComponent({ text, ellipsis: ell, } = measure( - contentRef.value?.$el, + findDOMNode(contentRef.value), { rows, suffix }, props.content, renderOperations(true), diff --git a/components/typography/Title.tsx b/components/typography/Title.tsx index 433859050..47fc57b94 100644 --- a/components/typography/Title.tsx +++ b/components/typography/Title.tsx @@ -8,7 +8,7 @@ const TITLE_ELE_LIST = tupleNum(1, 2, 3, 4, 5); export const titleProps = () => ({ ...omit(baseProps(), ['component', 'strong']), - level: Number as PropType, + level: Number as PropType<(typeof TITLE_ELE_LIST)[number]>, }); export type TitleProps = Partial>>; @@ -16,7 +16,7 @@ export type TitleProps = Partial> const Title: FunctionalComponent = (props, { slots, attrs }) => { const { level = 1, ...restProps } = props; let component: string; - if (TITLE_ELE_LIST.indexOf(level) !== -1) { + if (TITLE_ELE_LIST.includes(level)) { component = `h${level}`; } else { warning(false, 'Typography', 'Title only accept `1 | 2 | 3 | 4 | 5` as `level` value.'); diff --git a/components/typography/index.en-US.md b/components/typography/index.en-US.md index cc81c6081..08af07f16 100644 --- a/components/typography/index.en-US.md +++ b/components/typography/index.en-US.md @@ -3,7 +3,7 @@ category: Components type: General title: Typography cols: 1 -cover: https://gw.alipayobjects.com/zos/alicdn/GOM1KQ24O/Typography.svg +cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*MLt3R6m9huoAAAAAAAAAAAAADrJ8AQ/original --- Basic text writing, including headings, body text, lists, and more. diff --git a/components/typography/index.zh-CN.md b/components/typography/index.zh-CN.md index 94daa18e4..a1a0bae95 100644 --- a/components/typography/index.zh-CN.md +++ b/components/typography/index.zh-CN.md @@ -4,7 +4,7 @@ subtitle: 排版 type: 通用 title: Typography cols: 1 -cover: https://gw.alipayobjects.com/zos/alicdn/GOM1KQ24O/Typography.svg +cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*MLt3R6m9huoAAAAAAAAAAAAADrJ8AQ/original --- 文本的基本格式。