From 292780272e41740102eca2630a681887d137e67e Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 17 May 2017 14:35:02 +0100 Subject: [PATCH 1/2] Focus the description field in the inline form when mounted [ci skip] --- .../components/fields/description.vue | 5 ++- .../components/fields/description_spec.js | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 spec/javascripts/issue_show/components/fields/description_spec.js diff --git a/app/assets/javascripts/issue_show/components/fields/description.vue b/app/assets/javascripts/issue_show/components/fields/description.vue index b4c31811a0b..35b1ea6ff2b 100644 --- a/app/assets/javascripts/issue_show/components/fields/description.vue +++ b/app/assets/javascripts/issue_show/components/fields/description.vue @@ -20,6 +20,9 @@ components: { markdownField, }, + mounted() { + this.$refs.textarea.focus(); + }, }; @@ -39,7 +42,7 @@ data-supports-slash-commands="false" aria-label="Description" v-model="formState.description" - ref="textatea" + ref="textarea" slot="textarea"> diff --git a/spec/javascripts/issue_show/components/fields/description_spec.js b/spec/javascripts/issue_show/components/fields/description_spec.js new file mode 100644 index 00000000000..6ea52feb84f --- /dev/null +++ b/spec/javascripts/issue_show/components/fields/description_spec.js @@ -0,0 +1,34 @@ +import Vue from 'vue'; +import descriptionField from '~/issue_show/components/fields/description.vue'; + +describe('Description field component', () => { + let vm; + + beforeEach((done) => { + const Component = Vue.extend(descriptionField); + + // Needs an el in the DOM to be able to text the element is focused + const el = document.createElement('div'); + + document.body.appendChild(el); + + vm = new Component({ + el, + propsData: { + formState: { + description: '', + }, + markdownDocs: '/', + markdownPreviewUrl: '/', + }, + }).$mount(); + + Vue.nextTick(done); + }); + + it('focuses field when mounted', () => { + expect( + document.activeElement, + ).toBe(vm.$refs.textarea); + }); +}); From 9c9a24cee8d961fa33675b857f2ad980e20e0a4b Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Thu, 18 May 2017 09:12:44 +0100 Subject: [PATCH 2/2] Fixed typo --- .../issue_show/components/fields/description_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/javascripts/issue_show/components/fields/description_spec.js b/spec/javascripts/issue_show/components/fields/description_spec.js index 6ea52feb84f..cdb5c9ab862 100644 --- a/spec/javascripts/issue_show/components/fields/description_spec.js +++ b/spec/javascripts/issue_show/components/fields/description_spec.js @@ -7,7 +7,7 @@ describe('Description field component', () => { beforeEach((done) => { const Component = Vue.extend(descriptionField); - // Needs an el in the DOM to be able to text the element is focused + // Needs an el in the DOM to be able to test the element is focused const el = document.createElement('div'); document.body.appendChild(el);