Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix user stuck in title editing state #1430

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/components/common/EditableText.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
<span v-if="!props.isEditing">
{{ modelValue }}
</span>
<!-- Avoid double triggering finishEditing event when keyup.enter is triggered -->
<InputText
v-else
type="text"
size="small"
fluid
v-model:modelValue="inputValue"
ref="inputRef"
@keyup.enter="finishEditing"
@keyup.enter="blurInputElement"
@click.stop
:pt="{
root: {
Expand All @@ -37,21 +38,19 @@ const props = withDefaults(defineProps<EditableTextProps>(), {

const emit = defineEmits(['update:modelValue', 'edit'])
const inputValue = ref<string>(props.modelValue)
const isEditingFinished = ref<boolean>(false)
const inputRef = ref(null)

const blurInputElement = () => {
inputRef.value?.$el.blur()
}
const finishEditing = () => {
if (isEditingFinished.value) {
return
}
isEditingFinished.value = true
emit('edit', inputValue.value)
}
watch(
() => props.isEditing,
(newVal) => {
if (newVal) {
inputValue.value = props.modelValue
isEditingFinished.value = false
nextTick(() => {
if (!inputRef.value) return
const fileName = inputValue.value.includes('.')
Expand Down
6 changes: 4 additions & 2 deletions src/components/common/__tests__/EditableText.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ describe('EditableText', () => {
})
await wrapper.findComponent(InputText).setValue('New Text')
await wrapper.findComponent(InputText).trigger('keyup.enter')
expect(wrapper.emitted('edit')).toBeTruthy()
expect(wrapper.emitted('edit')[0]).toEqual(['New Text'])
// Blur event should have been triggered
expect(wrapper.findComponent(InputText).element).not.toBe(
document.activeElement
)
})

it('finishes editing on blur', async () => {
Expand Down
Loading