Commit 459a5055 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '12777-pressing-escape-should-close-the-designs' into 'master'

Resolve "Pressing `Escape` should close the Designs"

See merge request gitlab-org/gitlab-ee!15379
parents efbdb9ef 2cc82cbf
...@@ -59,7 +59,7 @@ export default { ...@@ -59,7 +59,7 @@ export default {
@input="$emit('input', $event.target.value)" @input="$emit('input', $event.target.value)"
@keydown.meta.enter="submitForm" @keydown.meta.enter="submitForm"
@keydown.ctrl.enter="submitForm" @keydown.ctrl.enter="submitForm"
@keydown.esc.exact="$emit('cancelForm')" @keyup.esc.stop="$emit('cancelForm')"
> >
</textarea> </textarea>
</markdown-field> </markdown-field>
......
<script> <script>
import Mousetrap from 'mousetrap';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { GlLoadingIcon } from '@gitlab/ui'; import { GlLoadingIcon } from '@gitlab/ui';
...@@ -83,6 +84,12 @@ export default { ...@@ -83,6 +84,12 @@ export default {
return this.discussions.length || this.annotationCoordinates; return this.discussions.length || this.annotationCoordinates;
}, },
}, },
mounted() {
Mousetrap.bind('esc', this.closeDesign);
},
beforeDestroy() {
Mousetrap.unbind('esc', this.closeDesign);
},
methods: { methods: {
addImageDiffNote() { addImageDiffNote() {
const { x, y, width, height } = this.annotationCoordinates; const { x, y, width, height } = this.annotationCoordinates;
...@@ -167,6 +174,11 @@ export default { ...@@ -167,6 +174,11 @@ export default {
this.overlayDimensions.width = position.width; this.overlayDimensions.width = position.width;
this.overlayDimensions.height = position.height; this.overlayDimensions.height = position.height;
}, },
closeDesign() {
// This needs to be changed to take a design version into account as soon as
// https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/15119 is merged
this.$router.push('/designs');
},
}, },
beforeRouteUpdate(to, from, next) { beforeRouteUpdate(to, from, next) {
this.closeCommentForm(); this.closeCommentForm();
......
---
title: Pressing the Escape key now closes designs in Design Management
merge_request: 15379
author:
type: added
...@@ -96,8 +96,8 @@ describe('Design reply form component', () => { ...@@ -96,8 +96,8 @@ describe('Design reply form component', () => {
expect(wrapper.emitted('input')).toBeTruthy(); expect(wrapper.emitted('input')).toBeTruthy();
}); });
it('emits cancelForm event on escape keydown on textarea', () => { it('emits cancelForm event on pressing escape button on textarea', () => {
findTextarea().trigger('keydown.esc'); findTextarea().trigger('keyup.esc');
expect(wrapper.emitted('cancelForm')).toBeTruthy(); expect(wrapper.emitted('cancelForm')).toBeTruthy();
}); });
......
...@@ -5,9 +5,13 @@ import DesignReplyForm from 'ee/design_management/components/design_notes/design ...@@ -5,9 +5,13 @@ import DesignReplyForm from 'ee/design_management/components/design_notes/design
import createImageDiffNoteMutation from 'ee/design_management/graphql/mutations/createImageDiffNote.mutation.graphql'; import createImageDiffNoteMutation from 'ee/design_management/graphql/mutations/createImageDiffNote.mutation.graphql';
import design from '../../mock_data/design'; import design from '../../mock_data/design';
jest.mock('mousetrap', () => ({
bind: jest.fn(),
unbind: jest.fn(),
}));
describe('Design management design index page', () => { describe('Design management design index page', () => {
let wrapper; let wrapper;
const newComment = 'new comment'; const newComment = 'new comment';
const annotationCoordinates = { const annotationCoordinates = {
x: 10, x: 10,
......
...@@ -6,6 +6,11 @@ import DesignDetail from 'ee/design_management/pages/design/index.vue'; ...@@ -6,6 +6,11 @@ import DesignDetail from 'ee/design_management/pages/design/index.vue';
import createRouter from 'ee/design_management/router'; import createRouter from 'ee/design_management/router';
import '~/commons/bootstrap'; import '~/commons/bootstrap';
jest.mock('mousetrap', () => ({
bind: jest.fn(),
unbind: jest.fn(),
}));
describe('Design management router', () => { describe('Design management router', () => {
let vm; let vm;
let router; let router;
......
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