Skip to content

Commit 22407fb

Browse files
committed
fix: shouldExcludeFromA11yTree runs in IE11
IE11 returns `undefined` for missing `parentElement`.
1 parent a401bb5 commit 22407fb

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/__tests__/role-helpers.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import {getRoles, logRoles, getImplicitAriaRoles} from '../role-helpers'
1+
import {
2+
getRoles,
3+
logRoles,
4+
getImplicitAriaRoles,
5+
shouldExcludeFromA11yTree,
6+
} from '../role-helpers'
27
import {render} from './helpers/test-utils'
38

49
beforeEach(() => {
@@ -57,6 +62,10 @@ function setup() {
5762
<li data-testid='b-list-item-1'>Item 1</li>
5863
<li data-testid='b-list-item-2'>Item 2</li>
5964
</ul>
65+
66+
<svg data-testid='a-svg'>
67+
<rect width="100" height="100" />
68+
</svg>
6069
</article>
6170
</section>
6271
`)
@@ -89,6 +98,7 @@ function setup() {
8998
input: getByTestId('a-input-1'),
9099
input2: getByTestId('a-input-2'),
91100
textarea: getByTestId('a-textarea'),
101+
svg: getByTestId('a-svg'),
92102
}
93103
}
94104

@@ -160,4 +170,10 @@ test('getImplicitAriaRoles returns expected roles for various dom nodes', () =>
160170
expect(getImplicitAriaRoles(input)).toEqual(['textbox'])
161171
})
162172

173+
test('shouldExcludeFromA11yTree handles SVGs', () => {
174+
const {svg} = setup()
175+
176+
expect(shouldExcludeFromA11yTree(svg)).toEqual(false)
177+
})
178+
163179
/* eslint no-console:0 */

src/role-helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function shouldExcludeFromA11yTree(element) {
2626
let visibility = computedStyle.visibility
2727

2828
let currentElement = element
29-
while (currentElement !== null) {
29+
while (currentElement) {
3030
if (currentElement.hidden === true) {
3131
return true
3232
}

0 commit comments

Comments
 (0)