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 {
@input="$emit('input', $event.target.value)"
@keydown.meta.enter="submitForm"
@keydown.ctrl.enter="submitForm"
@keydown.esc.exact="$emit('cancelForm')"
@keyup.esc.stop="$emit('cancelForm')"
>
</textarea>
</markdown-field>
......
<script>
import Mousetrap from 'mousetrap';
import createFlash from '~/flash';
import { s__ } from '~/locale';
import { GlLoadingIcon } from '@gitlab/ui';
......@@ -83,6 +84,12 @@ export default {
return this.discussions.length || this.annotationCoordinates;
},
},
mounted() {
Mousetrap.bind('esc', this.closeDesign);
},
beforeDestroy() {
Mousetrap.unbind('esc', this.closeDesign);
},
methods: {
addImageDiffNote() {
const { x, y, width, height } = this.annotationCoordinates;
......@@ -167,6 +174,11 @@ export default {
this.overlayDimensions.width = position.width;
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) {
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', () => {
expect(wrapper.emitted('input')).toBeTruthy();
});
it('emits cancelForm event on escape keydown on textarea', () => {
findTextarea().trigger('keydown.esc');
it('emits cancelForm event on pressing escape button on textarea', () => {
findTextarea().trigger('keyup.esc');
expect(wrapper.emitted('cancelForm')).toBeTruthy();
});
......
......@@ -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 design from '../../mock_data/design';
jest.mock('mousetrap', () => ({
bind: jest.fn(),
unbind: jest.fn(),
}));
describe('Design management design index page', () => {
let wrapper;
const newComment = 'new comment';
const annotationCoordinates = {
x: 10,
......
......@@ -6,6 +6,11 @@ import DesignDetail from 'ee/design_management/pages/design/index.vue';
import createRouter from 'ee/design_management/router';
import '~/commons/bootstrap';
jest.mock('mousetrap', () => ({
bind: jest.fn(),
unbind: jest.fn(),
}));
describe('Design management router', () => {
let vm;
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