-
Notifications
You must be signed in to change notification settings - Fork 2
Fix: AXE-1598 form element visible label #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rohitsahu-bstack
merged 4 commits into
release-5.1.0
from
AXE-1598-form-element-visible-label
Jun 25, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,104 @@ | ||
import { getNodeFromTree, memoize } from '../../core/utils'; | ||
import { sanitize } from '../text'; | ||
import { getIntersectionRect, getRectCenter, isPointInRect } from '../math'; | ||
import getOverflowHiddenAncestors from './get-overflow-hidden-ancestors'; | ||
import cache from '../../core/base/cache'; | ||
|
||
/** | ||
* Get the visible text client rects of a node. | ||
* @method getVisibleChildTextRect | ||
* @memberof axe.commons.dom | ||
* @instance | ||
* @param {Element} node | ||
*/ | ||
const getVisibleChildTextRect = memoize( | ||
function getVisibleChildTextRectMemoized(node) { | ||
const vNode = getNodeFromTree(node); | ||
const nodeRect = vNode.boundingClientRect; | ||
const clientRects = []; | ||
const overflowHiddenNodes = getOverflowHiddenAncestors(vNode); | ||
|
||
node.childNodes.forEach(textNode => { | ||
if (textNode.nodeType !== 3 || sanitize(textNode.nodeValue) === '') { | ||
return; | ||
} | ||
|
||
const contentRects = getContentRects(textNode); | ||
if (isOutsideNodeBounds(contentRects, nodeRect) && !cache.get('ruleId')) { | ||
return; | ||
} | ||
|
||
clientRects.push(...filterHiddenRects(contentRects, overflowHiddenNodes)); | ||
}); | ||
|
||
// a11y-engine-domforge change | ||
if (clientRects.length <= 0) { | ||
return []; | ||
} | ||
/** | ||
* if all text rects are larger than the bounds of the node, | ||
* or goes outside of the bounds of the node, we need to use | ||
* the nodes bounding rect so we stay within the bounds of the | ||
* element. | ||
* | ||
* @see https://github.com/dequelabs/axe-core/issues/2178 | ||
* @see https://github.com/dequelabs/axe-core/issues/2483 | ||
* @see https://github.com/dequelabs/axe-core/issues/2681 | ||
* | ||
* also need to resize the nodeRect to fit within the bounds of any overflow: hidden ancestors. | ||
* | ||
* @see https://github.com/dequelabs/axe-core/issues/4253 | ||
*/ | ||
return clientRects.length | ||
? clientRects | ||
: filterHiddenRects([nodeRect], overflowHiddenNodes); | ||
} | ||
); | ||
export default getVisibleChildTextRect; | ||
|
||
function getContentRects(node) { | ||
const range = document.createRange(); | ||
range.selectNodeContents(node); | ||
return Array.from(range.getClientRects()); | ||
} | ||
|
||
/** | ||
* Check to see if the text rect size is outside the of the | ||
* nodes bounding rect. Since we use the midpoint of the element | ||
* when determining the rect stack we will also use the midpoint | ||
* of the text rect to determine out of bounds | ||
*/ | ||
function isOutsideNodeBounds(rects, nodeRect) { | ||
return rects.some(rect => { | ||
const centerPoint = getRectCenter(rect); | ||
return !isPointInRect(centerPoint, nodeRect); | ||
}); | ||
} | ||
|
||
/** | ||
* Filter out 0 width and height rects (newline characters) and | ||
* any rects that are outside the bounds of overflow hidden | ||
* ancestors | ||
*/ | ||
function filterHiddenRects(contentRects, overflowHiddenNodes) { | ||
const visibleRects = []; | ||
contentRects.forEach(contentRect => { | ||
// ie11 has newline characters return 0.00998, so we'll say if the | ||
// line is < 1 it shouldn't be counted | ||
if (contentRect.width < 1 || contentRect.height < 1) { | ||
return; | ||
} | ||
|
||
// update the rect size to fit inside the bounds of all overflow | ||
// hidden ancestors | ||
const visibleRect = overflowHiddenNodes.reduce((rect, overflowNode) => { | ||
return rect && getIntersectionRect(rect, overflowNode.boundingClientRect); | ||
}, contentRect); | ||
|
||
if (visibleRect) { | ||
visibleRects.push(visibleRect); | ||
} | ||
}); | ||
|
||
return visibleRects; | ||
} |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.