Skip to content

Commit

Permalink
fix focusing of svg element with tabIndex (#6311)
Browse files Browse the repository at this point in the history
* fix svg element focusing on `tab` (closes #6262)

* skip IE11

* use nativeMethods
  • Loading branch information
AlexKamaev committed Jul 12, 2021
1 parent 0d31600 commit 36d5b37
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/client/core/utils/dom.js
Expand Up @@ -246,7 +246,7 @@ function getInvisibleElements (elements) {
}

function getTabIndexAttributeIntValue (el) {
let tabIndex = el.getAttribute('tabIndex');
let tabIndex = nativeMethods.getAttribute.call(el, 'tabindex');

if (tabIndex !== null) {
tabIndex = parseInt(tabIndex, 10);
Expand Down
42 changes: 42 additions & 0 deletions test/client/fixtures/automation/press-test.js
Expand Up @@ -159,6 +159,48 @@ $(document).ready(function () {
});
});

if (!browserUtils.isIE11) {
asyncTest('press tab to focus svg', function () {
const div = document.createElement('div');

div.innerHTML = '<button id="btn_prev_svg" tabindex="100">button 1</button>' +
'<svg id="svg_target" tabindex="101"><text x="0" y="15" fill="red">svg</text></svg>' +
'<button id="btn_after_svg" tabindex="102">button 2</button>';

const btn1 = div.querySelector('#btn_prev_svg');
const svg = div.querySelector('#svg_target');
const btn2 = div.querySelector('#btn_after_svg');

document.body.appendChild(div);

btn1.focus();
ok(btn1 === document.activeElement, document.activeElement.id + ' is focused');

let press = new PressAutomation(parseKeySequence('tab').combinations, {});

press
.run()
.then(function () {
ok(svg === document.activeElement, document.activeElement.id + ' is focused');

btn2.focus();
ok(btn2 === document.activeElement, document.activeElement.id + ' is focused');

press = new PressAutomation(parseKeySequence('shift+tab').combinations, {});

return press
.run();
})
.then(function () {
ok(svg === document.activeElement, document.activeElement.id + ' is focused');

document.body.removeChild(div);

start();
});
});
}

module('regression tests');

asyncTest('T334620, GH-3282 - Wrong "key" property in keyEvent objects (press)', function () {
Expand Down

0 comments on commit 36d5b37

Please sign in to comment.