fix: typography editing error, close #5743

pull/5750/head
tangjinzhou 2022-06-24 10:41:15 +08:00
parent bddf64e0ad
commit 39ac6ed89e
1 changed files with 20 additions and 10 deletions

View File

@ -30,6 +30,7 @@ import useConfigInject from '../_util/hooks/useConfigInject';
import type { EventHandler } from '../_util/EventInterface'; import type { EventHandler } from '../_util/EventInterface';
import omit from '../_util/omit'; import omit from '../_util/omit';
import type { AutoSizeType } from '../input/inputProps'; import type { AutoSizeType } from '../input/inputProps';
import useMergedState from '../_util/hooks/useMergedState';
export type BaseType = 'secondary' | 'success' | 'warning' | 'danger'; export type BaseType = 'secondary' | 'success' | 'warning' | 'danger';
@ -130,7 +131,6 @@ const Base = defineComponent({
const { prefixCls, direction } = useConfigInject('typography', props); const { prefixCls, direction } = useConfigInject('typography', props);
const state = reactive({ const state = reactive({
edit: false,
copied: false, copied: false,
ellipsisText: '', ellipsisText: '',
ellipsisContent: null, ellipsisContent: null,
@ -256,29 +256,39 @@ const Base = defineComponent({
}, 3000); }, 3000);
}); });
} }
const editable = computed(() => { const editable = computed(() => {
const editable = props.editable; const editable = props.editable;
if (!editable) return { editing: state.edit }; if (!editable) return { editing: false };
return { return {
editing: state.edit,
...(typeof editable === 'object' ? editable : null), ...(typeof editable === 'object' ? editable : null),
}; };
}); });
const [editing, setEditing] = useMergedState(false, {
value: computed(() => {
return editable.value.editing;
}),
});
function triggerEdit(edit: boolean) { function triggerEdit(edit: boolean) {
const { onStart } = editable.value; const { onStart } = editable.value;
if (edit && onStart) { if (edit && onStart) {
onStart(); onStart();
} }
state.edit = edit; setEditing(edit);
nextTick(() => { }
if (!edit) { watch(
editing,
val => {
if (!val) {
editIcon.value?.focus(); editIcon.value?.focus();
} }
}); },
} { flush: 'post' },
);
// ============== Ellipsis ============== // ============== Ellipsis ==============
function resizeOnNextFrame() { function resizeOnNextFrame() {
@ -467,7 +477,7 @@ const Base = defineComponent({
} }
return () => { return () => {
const { editing, triggerType = ['icon'] } = editable.value; const { triggerType = ['icon'] } = editable.value;
const children = const children =
props.ellipsis || props.editable props.ellipsis || props.editable
? props.content !== undefined ? props.content !== undefined
@ -477,7 +487,7 @@ const Base = defineComponent({
? slots.default() ? slots.default()
: props.content; : props.content;
if (editing) { if (editing.value) {
return renderEditInput(); return renderEditInput();
} }
return ( return (