Fixed the preview keyboard shortcut focusing wrong tab

Closes #31101
This commit is contained in:
Phil Hughes 2017-04-21 14:19:08 +01:00
parent f09f753908
commit b8a96fda9c
3 changed files with 38 additions and 2 deletions

View File

@ -57,8 +57,11 @@ import findAndFollowLink from './shortcuts_dashboard_navigation';
Shortcuts.prototype.toggleMarkdownPreview = function(e) {
// Check if short-cut was triggered while in Write Mode
if ($(e.target).hasClass('js-note-text')) {
$('.js-md-preview-button').focus();
const $target = $(e.target);
const $form = $target.closest('form');
if ($target.hasClass('js-note-text')) {
$('.js-md-preview-button', $form).focus();
}
return $(document).triggerHandler('markdown-preview:toggle', [e]);
};

View File

@ -0,0 +1,4 @@
---
title: Fixued preview shortcut focusing wrong preview tab
merge_request:
author:

View File

@ -0,0 +1,29 @@
/* global Shortcuts */
describe('Shortcuts', () => {
const fixtureName = 'issues/open-issue.html.raw';
preloadFixtures(fixtureName);
describe('toggleMarkdownPreview', () => {
let sc;
let event;
beforeEach(() => {
loadFixtures(fixtureName);
spyOnEvent('.js-md-preview-button', 'focus');
event = $.Event('', {
target: document.querySelector('.js-note-text'),
});
sc = new Shortcuts();
});
it('focuses preview button in form', () => {
sc.toggleMarkdownPreview(event);
expect('focus').toHaveBeenTriggeredOn('.js-md-preview-button');
});
});
});