Skip to content

Commit b68bb81

Browse files
committed
refactor: typography
1 parent c889882 commit b68bb81

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

components/typography/Base.tsx

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import EditOutlined from '@ant-design/icons-vue/EditOutlined';
1717
import {
1818
defineComponent,
1919
VNodeTypes,
20-
VNode,
2120
reactive,
2221
ref,
2322
onMounted,
@@ -170,14 +169,6 @@ const Base = defineComponent<InternalBlockProps>({
170169
}
171170
});
172171

173-
function saveTypographyRef(node: VNode) {
174-
contentRef.value = node;
175-
}
176-
177-
function saveEditIconRef(node: VNode) {
178-
editIcon.value = node;
179-
}
180-
181172
function getChildrenText(): string {
182173
return props.ellipsis || props.editable ? props.content : contentRef.value?.$el?.innerText;
183174
}
@@ -208,6 +199,7 @@ const Base = defineComponent<InternalBlockProps>({
208199
}
209200

210201
function onEditCancel() {
202+
editable.value.onCancel?.();
211203
triggerEdit(false);
212204
}
213205

@@ -375,7 +367,7 @@ const Base = defineComponent<InternalBlockProps>({
375367
return (
376368
<Tooltip key="edit" title={tooltip === false ? '' : title}>
377369
<TransButton
378-
ref={saveEditIconRef}
370+
ref={editIcon}
379371
class={`${prefixCls.value}-edit`}
380372
onClick={onEditClick}
381373
aria-label={ariaLabel}
@@ -418,7 +410,7 @@ const Base = defineComponent<InternalBlockProps>({
418410

419411
function renderEditInput() {
420412
const { class: className, style } = attrs;
421-
const { maxlength, autoSize } = editable.value;
413+
const { maxlength, autoSize, onEnd } = editable.value;
422414

423415
return (
424416
<Editable
@@ -432,6 +424,7 @@ const Base = defineComponent<InternalBlockProps>({
432424
onSave={onEditChange}
433425
onChange={onContentChange}
434426
onCancel={onEditCancel}
427+
onEnd={onEnd}
435428
/>
436429
);
437430
}
@@ -529,13 +522,16 @@ const Base = defineComponent<InternalBlockProps>({
529522
return (
530523
<ResizeObserver onResize={resizeOnNextFrame} disabled={!rows}>
531524
<Typography
532-
ref={saveTypographyRef}
525+
ref={contentRef}
533526
class={[
534-
{ [`${prefixCls.value}-${type}`]: type },
535-
{ [`${prefixCls.value}-disabled`]: disabled },
536-
{ [`${prefixCls.value}-ellipsis`]: rows },
537-
{ [`${prefixCls.value}-ellipsis-single-line`]: cssTextOverflow },
538-
{ [`${prefixCls.value}-ellipsis-multiple-line`]: cssLineClamp },
527+
{
528+
[`${prefixCls.value}-${type}`]: type,
529+
[`${prefixCls.value}-disabled`]: disabled,
530+
[`${prefixCls.value}-ellipsis`]: rows,
531+
[`${prefixCls.value}-single-line`]: rows === 1,
532+
[`${prefixCls.value}-ellipsis-single-line`]: cssTextOverflow,
533+
[`${prefixCls.value}-ellipsis-multiple-line`]: cssLineClamp,
534+
},
539535
className,
540536
]}
541537
style={{

components/typography/style/index.less

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,12 @@
259259
}
260260

261261
// ============ Ellipsis ============
262+
&-single-line {
263+
white-space: nowrap;
264+
}
265+
262266
&-ellipsis-single-line {
263267
overflow: hidden;
264-
white-space: nowrap;
265268
text-overflow: ellipsis;
266269

267270
// https://blog.csdn.net/iefreer/article/details/50421025

0 commit comments

Comments
 (0)