Commit 25be580b authored by Robert Hunt's avatar Robert Hunt

Merge branch 'ahmetkaramercan17-master-patch-18116' into 'master'

Updates the template button to support correct
tabbing and a focus state

Changelog: added
MR: !80925
parents eec06336 cb72a8ec
......@@ -3,6 +3,7 @@ import { debounce } from 'lodash';
import DEFAULT_PROJECT_TEMPLATES from 'ee_else_ce/projects/default_project_templates';
import { confirmAction } from '~/lib/utils/confirm_via_gl_modal/confirm_via_gl_modal';
import { DEFAULT_DEBOUNCE_AND_THROTTLE_MS } from '../lib/utils/constants';
import { ENTER_KEY } from '../lib/utils/keys';
import axios from '../lib/utils/axios_utils';
import {
convertToTitleCase,
......@@ -182,7 +183,11 @@ const bindEvents = () => {
$projectTemplateButtons.addClass('hidden');
$projectFieldsForm.addClass('selected');
$selectedIcon.empty();
const value = $(this).val();
const $selectedTemplate = $(this);
$selectedTemplate.prop('checked', true);
const value = $selectedTemplate.val();
const selectedTemplate = DEFAULT_PROJECT_TEMPLATES[value];
$selectedTemplateText.text(selectedTemplate.text);
......@@ -194,7 +199,21 @@ const bindEvents = () => {
setProjectNamePathHandlers($activeTabProjectName, $activeTabProjectPath);
}
$useTemplateBtn.on('change', chooseTemplate);
function toggleActiveClassOnLabel(event) {
const $label = $(event.target).parent();
$label.toggleClass('active');
}
function chooseTemplateOnEnter(event) {
if (event.code === ENTER_KEY) {
chooseTemplate.call(this);
}
}
$useTemplateBtn.on('click', chooseTemplate);
$useTemplateBtn.on('focus focusout', toggleActiveClassOnLabel);
$useTemplateBtn.on('keypress', chooseTemplateOnEnter);
$changeTemplateBtn.on('click', () => {
$projectTemplateButtons.removeClass('hidden');
......
......@@ -15,6 +15,12 @@ RSpec.describe 'Project' do
end
shared_examples 'creates from template' do |template, sub_template_tab = nil|
let(:selected_template) { page.find('.project-fields-form .selected-template') }
choose_template_selector = '.choose-template'
template_option_selector = '.template-option'
template_name_selector = '.description strong'
it "is created from template", :js do
click_link 'Create from template'
find(".project-template #{sub_template_tab}").click if sub_template_tab
......@@ -27,6 +33,39 @@ RSpec.describe 'Project' do
expect(page).to have_content template.name
end
it 'is created using keyboard navigation', :js do
click_link 'Create from template'
first_template = first(template_option_selector)
first_template_name = first_template.find(template_name_selector).text
first_template.find(choose_template_selector).click
expect(selected_template).to have_text(first_template_name)
click_button "Change template"
find("#built-in").click
# Jumps down 1 template, skipping the `preview` buttons
2.times do
page.send_keys :tab
end
# Ensure the template with focus is selected
project_name = "project from template"
focused_template = page.find(':focus').ancestor(template_option_selector)
focused_template_name = focused_template.find(template_name_selector).text
focused_template.find(choose_template_selector).send_keys :enter
fill_in "project_name", with: project_name
expect(selected_template).to have_text(focused_template_name)
page.within '#content-body' do
click_button "Create project"
end
expect(page).to have_content project_name
end
end
context 'create with project template' do
......
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