Commit 9c35162f authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'form-focus-previous-incorrect-form' into 'master'

Fixed the preview keyboard shortcut focusing wrong tab

Closes #31101

See merge request !10849
parents d3a788da f5f97359
...@@ -57,8 +57,11 @@ import findAndFollowLink from './shortcuts_dashboard_navigation'; ...@@ -57,8 +57,11 @@ import findAndFollowLink from './shortcuts_dashboard_navigation';
Shortcuts.prototype.toggleMarkdownPreview = function(e) { Shortcuts.prototype.toggleMarkdownPreview = function(e) {
// Check if short-cut was triggered while in Write Mode // Check if short-cut was triggered while in Write Mode
if ($(e.target).hasClass('js-note-text')) { const $target = $(e.target);
$('.js-md-preview-button').focus(); const $form = $target.closest('form');
if ($target.hasClass('js-note-text')) {
$('.js-md-preview-button', $form).focus();
} }
return $(document).triggerHandler('markdown-preview:toggle', [e]); return $(document).triggerHandler('markdown-preview:toggle', [e]);
}; };
......
---
title: Fixued preview shortcut focusing wrong preview tab
merge_request:
author:
/* global Shortcuts */
describe('Shortcuts', () => {
const fixtureName = 'issues/issue_with_comment.html.raw';
const createEvent = (type, target) => $.Event(type, {
target,
});
preloadFixtures(fixtureName);
describe('toggleMarkdownPreview', () => {
let sc;
beforeEach(() => {
loadFixtures(fixtureName);
spyOnEvent('.js-new-note-form .js-md-preview-button', 'focus');
spyOnEvent('.edit-note .js-md-preview-button', 'focus');
sc = new Shortcuts();
});
it('focuses preview button in form', () => {
sc.toggleMarkdownPreview(
createEvent('KeyboardEvent', document.querySelector('.js-new-note-form .js-note-text'),
));
expect('focus').toHaveBeenTriggeredOn('.js-new-note-form .js-md-preview-button');
});
it('focues preview button inside edit comment form', (done) => {
document.querySelector('.js-note-edit').click();
setTimeout(() => {
sc.toggleMarkdownPreview(
createEvent('KeyboardEvent', document.querySelector('.edit-note .js-note-text'),
));
expect('focus').not.toHaveBeenTriggeredOn('.js-new-note-form .js-md-preview-button');
expect('focus').toHaveBeenTriggeredOn('.edit-note .js-md-preview-button');
done();
});
});
});
});
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