Commit 6d4e8154 authored by Phil Hughes's avatar Phil Hughes

Fixes ctrl+enter not submit issue edit form

Closes #33758
parent 801cf923
...@@ -47,7 +47,8 @@ ...@@ -47,7 +47,8 @@
ref="textarea" ref="textarea"
slot="textarea" slot="textarea"
placeholder="Write a comment or drag your files here..." placeholder="Write a comment or drag your files here..."
@keydown.meta.enter="updateIssuable"> @keydown.meta.enter="updateIssuable"
@keydown.ctrl.enter="updateIssuable">
</textarea> </textarea>
</markdown-field> </markdown-field>
</div> </div>
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
placeholder="Issue title" placeholder="Issue title"
aria-label="Issue title" aria-label="Issue title"
v-model="formState.title" v-model="formState.title"
@keydown.meta.enter="updateIssuable" /> @keydown.meta.enter="updateIssuable"
@keydown.ctrl.enter="updateIssuable" />
</fieldset> </fieldset>
</template> </template>
---
title: Fixed ctrl+enter not submit issue edit form
merge_request:
author:
import Vue from 'vue'; import Vue from 'vue';
import eventHub from '~/issue_show/event_hub';
import Store from '~/issue_show/stores'; import Store from '~/issue_show/stores';
import descriptionField from '~/issue_show/components/fields/description.vue'; import descriptionField from '~/issue_show/components/fields/description.vue';
import { keyboardDownEvent } from '../../helpers';
describe('Description field component', () => { describe('Description field component', () => {
let vm; let vm;
...@@ -18,6 +20,8 @@ describe('Description field component', () => { ...@@ -18,6 +20,8 @@ describe('Description field component', () => {
document.body.appendChild(el); document.body.appendChild(el);
spyOn(eventHub, '$emit');
vm = new Component({ vm = new Component({
el, el,
propsData: { propsData: {
...@@ -53,4 +57,20 @@ describe('Description field component', () => { ...@@ -53,4 +57,20 @@ describe('Description field component', () => {
document.activeElement, document.activeElement,
).toBe(vm.$refs.textarea); ).toBe(vm.$refs.textarea);
}); });
it('triggers update with meta+enter', () => {
vm.$el.querySelector('.md-area textarea').dispatchEvent(keyboardDownEvent(13, true));
expect(
eventHub.$emit,
).toHaveBeenCalled();
});
it('triggers update with ctrl+enter', () => {
vm.$el.querySelector('.md-area textarea').dispatchEvent(keyboardDownEvent(13, false, true));
expect(
eventHub.$emit,
).toHaveBeenCalled();
});
}); });
import Vue from 'vue'; import Vue from 'vue';
import eventHub from '~/issue_show/event_hub';
import Store from '~/issue_show/stores'; import Store from '~/issue_show/stores';
import titleField from '~/issue_show/components/fields/title.vue'; import titleField from '~/issue_show/components/fields/title.vue';
import { keyboardDownEvent } from '../../helpers';
describe('Title field component', () => { describe('Title field component', () => {
let vm; let vm;
...@@ -15,6 +17,8 @@ describe('Title field component', () => { ...@@ -15,6 +17,8 @@ describe('Title field component', () => {
}); });
store.formState.title = 'test'; store.formState.title = 'test';
spyOn(eventHub, '$emit');
vm = new Component({ vm = new Component({
propsData: { propsData: {
formState: store.formState, formState: store.formState,
...@@ -27,4 +31,20 @@ describe('Title field component', () => { ...@@ -27,4 +31,20 @@ describe('Title field component', () => {
vm.$el.querySelector('.form-control').value, vm.$el.querySelector('.form-control').value,
).toBe('test'); ).toBe('test');
}); });
it('triggers update with meta+enter', () => {
vm.$el.querySelector('.form-control').dispatchEvent(keyboardDownEvent(13, true));
expect(
eventHub.$emit,
).toHaveBeenCalled();
});
it('triggers update with ctrl+enter', () => {
vm.$el.querySelector('.form-control').dispatchEvent(keyboardDownEvent(13, false, true));
expect(
eventHub.$emit,
).toHaveBeenCalled();
});
}); });
// eslint-disable-next-line import/prefer-default-export
export const keyboardDownEvent = (code, metaKey = false, ctrlKey = false) => {
const e = new CustomEvent('keydown');
e.keyCode = code;
e.metaKey = metaKey;
e.ctrlKey = ctrlKey;
return e;
};
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