Skip to content

Commit 7f2b374

Browse files
committed
Merge branch 'ACP2E-1542' of https://github.com/magento-l3/magento2-page-builder into PR-02142023
2 parents c07a84b + 774ba63 commit 7f2b374

File tree

2 files changed

+86
-1
lines changed
  • app/code/Magento/PageBuilder/view/adminhtml/web/js/form/element
  • dev/tests/js/jasmine/tests/app/code/Magento/PageBuilder/adminhtml/web/js/form/element

2 files changed

+86
-1
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/js/form/element/wysiwyg.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,26 @@ define([
131131
editableValue = this.pageBuilder.isFullScreen();
132132

133133
editable.attr('contenteditable', editableValue);
134-
$(pageBuilderSelector + focusableSelector).attr('tabindex', tabIndexValue);
134+
if (this.pageBuilder.isFullScreen()) {
135+
$(pageBuilderSelector + focusableSelector)
136+
.each(function () {
137+
if ($(this).data('original-tabindex')) {
138+
$(this).attr('tabindex', $(this).data('original-tabindex'));
139+
} else if ($(this).data('original-tabindex') === '') {
140+
$(this).removeAttr('tabindex');
141+
}
142+
$(this).removeData('original-tabindex');
143+
});
144+
} else {
145+
$(pageBuilderSelector + focusableSelector).each(function () {
146+
if ($(this).attr('tabindex')) {
147+
$(this).data('original-tabindex', $(this).attr('tabindex'));
148+
} else {
149+
$(this).data('original-tabindex', '');
150+
}
151+
$(this).attr('tabindex', '-1');
152+
});
153+
}
135154
$(mediaSelector).attr('tabindex', tabIndexValue);
136155
},
137156

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
*
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/* eslint-disable max-nested-callbacks */
8+
define([
9+
'jquery',
10+
'Magento_PageBuilder/js/form/element/wysiwyg'
11+
], function ($, UiWysiwyg) {
12+
'use strict';
13+
14+
var wysiwyg;
15+
16+
function createWysiwygMock() {
17+
var mock,
18+
MockWysiwyg = function () {};
19+
20+
MockWysiwyg.prototype = Object.create(UiWysiwyg.prototype);
21+
MockWysiwyg.prototype.constructor = MockWysiwyg;
22+
mock = new MockWysiwyg();
23+
$.extend(mock, UiWysiwyg.defaults);
24+
return mock;
25+
}
26+
27+
beforeEach(function () {
28+
wysiwyg = createWysiwygMock();
29+
wysiwyg.pageBuilder = {id: 'pb-wysiwyg-test'};
30+
$(document.body).append(
31+
$('<div><div contenteditable="true"><a href="/login"></a><span tabindex="0"></span></div></div>')
32+
.attr('id', wysiwyg.pageBuilder.id)
33+
);
34+
});
35+
36+
afterEach(function () {
37+
$('#' + wysiwyg.pageBuilder.id).remove();
38+
});
39+
40+
describe('Magento_PageBuilder/js/form/element/wysiwyg', function () {
41+
describe('toggleFocusableElements', function () {
42+
it('Should restore tabindex and contenteditable in fullscreen mode', function () {
43+
var $div = $('#' + wysiwyg.pageBuilder.id);
44+
45+
wysiwyg.pageBuilder.isFullScreen = jasmine.createSpy().and.returnValue(false);
46+
wysiwyg.toggleFocusableElements();
47+
expect($div.find('a').attr('tabindex')).toBe('-1');
48+
expect($div.find('a').data('original-tabindex')).toBe('');
49+
expect($div.find('span').attr('tabindex')).toBe('-1');
50+
expect($div.find('span').data('original-tabindex')).toBe('0');
51+
expect($div.find('[contenteditable]').attr('contenteditable')).toBe('false');
52+
53+
// check full screen mode
54+
wysiwyg.pageBuilder.isFullScreen = jasmine.createSpy().and.returnValue(true);
55+
wysiwyg.toggleFocusableElements();
56+
// check that taindex is removed from "a"
57+
expect($div.find('a').attr('tabindex')).toBe(undefined);
58+
expect($div.find('a').data('original-tabindex')).toBe(undefined);
59+
// check that taindex is restored for "span"
60+
expect($div.find('span').attr('tabindex')).toBe('0');
61+
expect($div.find('span').data('original-tabindex')).toBe(undefined);
62+
expect($div.find('[contenteditable]').attr('contenteditable')).toBe('true');
63+
});
64+
});
65+
});
66+
});

0 commit comments

Comments
 (0)