-
Notifications
You must be signed in to change notification settings - Fork 779
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dom.focusDisabled,dom.isVisibleForScreenreader): support the ine…
…rt attribute (#3857) * feat(dom.focus-disabled,dom.is-visible-for-screenreader): support the inert attribute * typos * integration tests
- Loading branch information
Showing
10 changed files
with
153 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import memoize from '../../core/utils/memoize'; | ||
|
||
/** | ||
* Determines if an element is inside an inert subtree. | ||
* @param {VirtualNode} vNode | ||
* @param {Boolean} [options.skipAncestors] If the ancestor tree should not be used | ||
* @return {Boolean} The element's inert state | ||
*/ | ||
export default function isInert(vNode, { skipAncestors } = {}) { | ||
if (skipAncestors) { | ||
return isInertSelf(vNode); | ||
} | ||
|
||
return isInertAncestors(vNode); | ||
} | ||
|
||
/** | ||
* Check the element for inert | ||
*/ | ||
const isInertSelf = memoize(function isInertSelfMemoized(vNode) { | ||
return vNode.hasAttr('inert'); | ||
}); | ||
|
||
/** | ||
* Check the element and ancestors for inert | ||
*/ | ||
const isInertAncestors = memoize(function isInertAncestorsMemoized(vNode) { | ||
if (isInertSelf(vNode)) { | ||
return true; | ||
} | ||
|
||
if (!vNode.parent) { | ||
return false; | ||
} | ||
|
||
return isInertAncestors(vNode.parent); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
describe('dom.isInert', () => { | ||
const isInert = axe.commons.dom.isInert; | ||
const { queryFixture } = axe.testUtils; | ||
|
||
it('returns true for element with "inert=false`', () => { | ||
const vNode = queryFixture('<div id="target" inert="false"></div>'); | ||
|
||
assert.isTrue(isInert(vNode)); | ||
}); | ||
|
||
it('returns true for element with "inert`', () => { | ||
const vNode = queryFixture('<div id="target" inert></div>'); | ||
|
||
assert.isTrue(isInert(vNode)); | ||
}); | ||
|
||
it('returns false for element without inert', () => { | ||
const vNode = queryFixture('<div id="target"></div>'); | ||
|
||
assert.isFalse(isInert(vNode)); | ||
}); | ||
|
||
it('returns true for ancestor with inert', () => { | ||
const vNode = queryFixture( | ||
'<div inert><div><div id="target"></div></div></div>' | ||
); | ||
|
||
assert.isTrue(isInert(vNode)); | ||
}); | ||
|
||
describe('options.skipAncestors', () => { | ||
it('returns false for ancestor with inert', () => { | ||
const vNode = queryFixture( | ||
'<div inert><div><div id="target"></div></div></div>' | ||
); | ||
|
||
assert.isFalse(isInert(vNode, { skipAncestors: true })); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters