Commit 3816b49d authored by Natalia Tepluhina's avatar Natalia Tepluhina Committed by Nicolò Maria Mezzopera

Input field for new design discussion should remain focused

parent 5cbcc865
...@@ -62,7 +62,7 @@ export default { ...@@ -62,7 +62,7 @@ export default {
}, },
}, },
mounted() { mounted() {
this.$refs.textarea.focus(); this.focusInput();
}, },
methods: { methods: {
submitForm() { submitForm() {
...@@ -75,6 +75,9 @@ export default { ...@@ -75,6 +75,9 @@ export default {
this.$emit('cancelForm'); this.$emit('cancelForm');
} }
}, },
focusInput() {
this.$refs.textarea.focus();
},
}, },
}; };
</script> </script>
......
...@@ -254,6 +254,9 @@ export default { ...@@ -254,6 +254,9 @@ export default {
}, },
openCommentForm(annotationCoordinates) { openCommentForm(annotationCoordinates) {
this.annotationCoordinates = annotationCoordinates; this.annotationCoordinates = annotationCoordinates;
if (this.$refs.newDiscussionForm) {
this.$refs.newDiscussionForm.focusInput();
}
}, },
closeCommentForm() { closeCommentForm() {
this.comment = ''; this.comment = '';
...@@ -361,6 +364,7 @@ export default { ...@@ -361,6 +364,7 @@ export default {
@error="onCreateImageDiffNoteError" @error="onCreateImageDiffNoteError"
> >
<design-reply-form <design-reply-form
ref="newDiscussionForm"
v-model="comment" v-model="comment"
:is-saving="loading" :is-saving="loading"
:markdown-preview-path="markdownPreviewPath" :markdown-preview-path="markdownPreviewPath"
......
---
title: When clicking multiple times to leave a single comment, the input field should
remain focused
merge_request: 33742
author:
type: fixed
...@@ -5,7 +5,7 @@ import { ApolloMutation } from 'vue-apollo'; ...@@ -5,7 +5,7 @@ import { ApolloMutation } from 'vue-apollo';
import createFlash from '~/flash'; import createFlash from '~/flash';
import DesignIndex from '~/design_management/pages/design/index.vue'; import DesignIndex from '~/design_management/pages/design/index.vue';
import DesignSidebar from '~/design_management/components/design_sidebar.vue'; import DesignSidebar from '~/design_management/components/design_sidebar.vue';
import DesignReplyForm from '~/design_management/components/design_notes/design_reply_form.vue'; import DesignPresentation from '~/design_management/components/design_presentation.vue';
import createImageDiffNoteMutation from '~/design_management/graphql/mutations/createImageDiffNote.mutation.graphql'; import createImageDiffNoteMutation from '~/design_management/graphql/mutations/createImageDiffNote.mutation.graphql';
import design from '../../mock_data/design'; import design from '../../mock_data/design';
import mockResponseWithDesigns from '../../mock_data/designs'; import mockResponseWithDesigns from '../../mock_data/designs';
...@@ -26,6 +26,15 @@ jest.mock('mousetrap', () => ({ ...@@ -26,6 +26,15 @@ jest.mock('mousetrap', () => ({
unbind: jest.fn(), unbind: jest.fn(),
})); }));
const focusInput = jest.fn();
const DesignReplyForm = {
template: '<div><textarea ref="textarea"></textarea></div>',
methods: {
focusInput,
},
};
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(VueRouter); localVue.use(VueRouter);
...@@ -64,6 +73,7 @@ describe('Design management design index page', () => { ...@@ -64,6 +73,7 @@ describe('Design management design index page', () => {
const findDiscussionForm = () => wrapper.find(DesignReplyForm); const findDiscussionForm = () => wrapper.find(DesignReplyForm);
const findSidebar = () => wrapper.find(DesignSidebar); const findSidebar = () => wrapper.find(DesignSidebar);
const findDesignPresentation = () => wrapper.find(DesignPresentation);
function createComponent(loading = false, data = {}) { function createComponent(loading = false, data = {}) {
const $apollo = { const $apollo = {
...@@ -83,6 +93,7 @@ describe('Design management design index page', () => { ...@@ -83,6 +93,7 @@ describe('Design management design index page', () => {
stubs: { stubs: {
ApolloMutation, ApolloMutation,
DesignSidebar, DesignSidebar,
DesignReplyForm,
}, },
data() { data() {
return { return {
...@@ -153,13 +164,29 @@ describe('Design management design index page', () => { ...@@ -153,13 +164,29 @@ describe('Design management design index page', () => {
}, },
}); });
wrapper.vm.openCommentForm({ x: 0, y: 0 }); findDesignPresentation().vm.$emit('openCommentForm', { x: 0, y: 0 });
return wrapper.vm.$nextTick().then(() => { return wrapper.vm.$nextTick().then(() => {
expect(findDiscussionForm().exists()).toBe(true); expect(findDiscussionForm().exists()).toBe(true);
}); });
}); });
it('keeps new discussion form focused', () => {
createComponent(false, {
design: {
...design,
discussions: {
nodes: [],
},
},
annotationCoordinates,
});
findDesignPresentation().vm.$emit('openCommentForm', { x: 10, y: 10 });
expect(focusInput).toHaveBeenCalled();
});
it('sends a mutation on submitting form and closes form', () => { it('sends a mutation on submitting form and closes form', () => {
createComponent(false, { createComponent(false, {
design: { design: {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment