Commit b6e17069 authored by Phil Hughes's avatar Phil Hughes

Merge branch '288327-wiki-edit-automatically-focus-on-the-title-field' into 'master'

Resolve "Wiki edit: automatically focus on the content field"

See merge request gitlab-org/gitlab!50941
parents 9dc7d230 f964a2d8
...@@ -67,6 +67,7 @@ export default class GLForm { ...@@ -67,6 +67,7 @@ export default class GLForm {
addMarkdownListeners(this.form); addMarkdownListeners(this.form);
this.form.show(); this.form.show();
if (this.isAutosizeable) this.setupAutosize(); if (this.isAutosizeable) this.setupAutosize();
if (this.textarea.data('autofocus') === true) this.textarea.focus();
} }
setupAutosize() { setupAutosize() {
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
- supports_autocomplete = local_assigns.fetch(:supports_autocomplete, true) - supports_autocomplete = local_assigns.fetch(:supports_autocomplete, true)
- supports_quick_actions = local_assigns.fetch(:supports_quick_actions, false) - supports_quick_actions = local_assigns.fetch(:supports_quick_actions, false)
- qa_selector = local_assigns.fetch(:qa_selector, '') - qa_selector = local_assigns.fetch(:qa_selector, '')
- autofocus = local_assigns.fetch(:autofocus, false)
.zen-backdrop .zen-backdrop
- classes << ' js-gfm-input js-autosize markdown-area' - classes << ' js-gfm-input js-autosize markdown-area'
- if defined?(f) && f - if defined?(f) && f
...@@ -12,7 +13,8 @@ ...@@ -12,7 +13,8 @@
dir: 'auto', dir: 'auto',
data: { supports_quick_actions: supports_quick_actions, data: { supports_quick_actions: supports_quick_actions,
supports_autocomplete: supports_autocomplete, supports_autocomplete: supports_autocomplete,
qa_selector: qa_selector } qa_selector: qa_selector,
autofocus: autofocus }
- else - else
= text_area_tag attr, current_text, data: { qa_selector: qa_selector }, class: classes, placeholder: placeholder = text_area_tag attr, current_text, data: { qa_selector: qa_selector }, class: classes, placeholder: placeholder
%a.zen-control.zen-control-leave.js-zen-leave.gl-text-gray-500{ href: "#" } %a.zen-control.zen-control-leave.js-zen-leave.gl-text-gray-500{ href: "#" }
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
.col-sm-2.col-form-label= f.label :content, class: 'control-label-full-width' .col-sm-2.col-form-label= f.label :content, class: 'control-label-full-width'
.col-sm-10 .col-sm-10
= render layout: 'shared/md_preview', locals: { url: wiki_page_path(@wiki, @page, action: :preview_markdown) } do = render layout: 'shared/md_preview', locals: { url: wiki_page_path(@wiki, @page, action: :preview_markdown) } do
= render 'shared/zen', f: f, attr: :content, classes: 'note-textarea qa-wiki-content-textarea', placeholder: s_("WikiPage|Write your content or drag files here…") = render 'shared/zen', f: f, attr: :content, classes: 'note-textarea qa-wiki-content-textarea', placeholder: s_("WikiPage|Write your content or drag files here…"), autofocus: @page.persisted?
= render 'shared/notes/hints' = render 'shared/notes/hints'
.clearfix .clearfix
......
---
title: 'Wiki edit: automatically focus on the content field'
merge_request: 50941
author: Jacopo Beschi @jacopo-beschi
type: changed
...@@ -114,6 +114,26 @@ describe('GLForm', () => { ...@@ -114,6 +114,26 @@ describe('GLForm', () => {
}); });
}); });
describe('autofocus', () => {
it('focus the textarea when autofocus is true', () => {
testContext.textarea.data('autofocus', true);
jest.spyOn($.prototype, 'focus');
testContext.glForm = new GLForm(testContext.form, false);
expect($.prototype.focus).toHaveBeenCalled();
});
it("doesn't focus the textarea when autofocus is false", () => {
testContext.textarea.data('autofocus', false);
jest.spyOn($.prototype, 'focus');
testContext.glForm = new GLForm(testContext.form, false);
expect($.prototype.focus).not.toHaveBeenCalled();
});
});
describe('supportsQuickActions', () => { describe('supportsQuickActions', () => {
it('should return false if textarea does not support quick actions', () => { it('should return false if textarea does not support quick actions', () => {
const glForm = new GLForm(testContext.form, false); const glForm = new GLForm(testContext.form, false);
......
...@@ -123,6 +123,10 @@ RSpec.shared_examples 'User updates wiki page' do ...@@ -123,6 +123,10 @@ RSpec.shared_examples 'User updates wiki page' do
expect(page).to have_content('Updated Wiki Content') expect(page).to have_content('Updated Wiki Content')
end end
it 'focuses on the content field', :js do
expect(page).to have_selector '.note-textarea:focus'
end
it 'cancels editing of a page' do it 'cancels editing of a page' do
page.within(:css, '.wiki-form .form-actions') do page.within(:css, '.wiki-form .form-actions') do
click_on('Cancel') click_on('Cancel')
......
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