diff --git a/lib/commons/text/accessible-text-virtual.js b/lib/commons/text/accessible-text-virtual.js index 99091b4fa3..ee6901551e 100644 --- a/lib/commons/text/accessible-text-virtual.js +++ b/lib/commons/text/accessible-text-virtual.js @@ -49,6 +49,10 @@ text.accessibleTextVirtual = function accessibleTextVirtual( // Find the first step that returns a non-empty string let accName = computationSteps.reduce((accName, step) => { + if (context.startNode === virtualNode) { + accName = text.sanitize(accName); + } + if (accName !== '') { // yes, whitespace only a11y names halt the algorithm return accName; @@ -56,10 +60,6 @@ text.accessibleTextVirtual = function accessibleTextVirtual( return step(virtualNode, context); }, ''); - if (context.startNode === virtualNode) { - accName = text.sanitize(accName); - } - if (context.debug) { axe.log(accName || '{empty-value}', actualNode, context); } diff --git a/test/commons/text/accessible-text.js b/test/commons/text/accessible-text.js index 18e072db83..efd3a4dddc 100644 --- a/test/commons/text/accessible-text.js +++ b/test/commons/text/accessible-text.js @@ -579,6 +579,15 @@ describe('text.accessibleTextVirtual', function() { assert.equal(axe.commons.text.accessibleTextVirtual(target), ''); }); + it('should not stop when attributes contain whitespace', function() { + fixture.innerHTML = + ''; + axe.testUtils.flatTreeSetup(fixture); + + var target = axe.utils.querySelectorAll(axe._tree, 'button')[0]; + assert.equal(axe.commons.text.accessibleTextVirtual(target), 'Hello World'); + }); + (shadowSupport.v1 ? it : xit)( 'should only find aria-labelledby element in the same context ', function() {