Skip to content

Commit 39ac6ed

Browse files
committed
fix: typography editing error, close #5743
1 parent bddf64e commit 39ac6ed

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

components/typography/Base.tsx

+20-10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import useConfigInject from '../_util/hooks/useConfigInject';
3030
import type { EventHandler } from '../_util/EventInterface';
3131
import omit from '../_util/omit';
3232
import type { AutoSizeType } from '../input/inputProps';
33+
import useMergedState from '../_util/hooks/useMergedState';
3334

3435
export type BaseType = 'secondary' | 'success' | 'warning' | 'danger';
3536

@@ -130,7 +131,6 @@ const Base = defineComponent({
130131
const { prefixCls, direction } = useConfigInject('typography', props);
131132

132133
const state = reactive({
133-
edit: false,
134134
copied: false,
135135
ellipsisText: '',
136136
ellipsisContent: null,
@@ -256,29 +256,39 @@ const Base = defineComponent({
256256
}, 3000);
257257
});
258258
}
259+
259260
const editable = computed(() => {
260261
const editable = props.editable;
261-
if (!editable) return { editing: state.edit };
262+
if (!editable) return { editing: false };
262263

263264
return {
264-
editing: state.edit,
265265
...(typeof editable === 'object' ? editable : null),
266266
};
267267
});
268268

269+
const [editing, setEditing] = useMergedState(false, {
270+
value: computed(() => {
271+
return editable.value.editing;
272+
}),
273+
});
274+
269275
function triggerEdit(edit: boolean) {
270276
const { onStart } = editable.value;
271277
if (edit && onStart) {
272278
onStart();
273279
}
274280

275-
state.edit = edit;
276-
nextTick(() => {
277-
if (!edit) {
281+
setEditing(edit);
282+
}
283+
watch(
284+
editing,
285+
val => {
286+
if (!val) {
278287
editIcon.value?.focus();
279288
}
280-
});
281-
}
289+
},
290+
{ flush: 'post' },
291+
);
282292

283293
// ============== Ellipsis ==============
284294
function resizeOnNextFrame() {
@@ -467,7 +477,7 @@ const Base = defineComponent({
467477
}
468478

469479
return () => {
470-
const { editing, triggerType = ['icon'] } = editable.value;
480+
const { triggerType = ['icon'] } = editable.value;
471481
const children =
472482
props.ellipsis || props.editable
473483
? props.content !== undefined
@@ -477,7 +487,7 @@ const Base = defineComponent({
477487
? slots.default()
478488
: props.content;
479489

480-
if (editing) {
490+
if (editing.value) {
481491
return renderEditInput();
482492
}
483493
return (

0 commit comments

Comments
 (0)