-
Notifications
You must be signed in to change notification settings - Fork 791
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
fix(target-size): update to match new spacing requirements #4117
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c51fc33
fix(target-size): update to match new spacing requirements
straker d37cc75
working
straker f290e95
Merge branch 'develop' into target-size-update
straker b77eaa9
tests
straker 27786b2
finalize?
straker c42db0a
tests
straker d8b44e3
revert playground
straker 1221833
:robot: Automated formatting fixes
straker b379498
Apply suggestions from code review
straker 2101fbe
:robot: Automated formatting fixes
straker 7ace8bb
udpate tests
straker 49c3038
dont half minOffset but double return from getOffset
straker faf1645
Apply suggestions from code review
straker 2037320
:robot: Automated formatting fixes
straker 12be400
Merge branch 'develop' into target-size-update
straker 0ee3b95
Merge branch 'target-size-update' of https://github.com/dequelabs/axe…
straker 582f5c9
fix tests
straker 1bdd71e
fix test
straker 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 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,66 @@ | ||
import findNearbyElms from './find-nearby-elms'; | ||
import { splitRects, hasVisualOverlap } from '../math'; | ||
import memoize from '../../core/utils/memoize'; | ||
|
||
const roundingMargin = 0.05; | ||
|
||
export default memoize(getTargetSize); | ||
|
||
/** | ||
* Compute the target size of an element. | ||
* @see https://www.w3.org/TR/WCAG22/#dfn-targets | ||
*/ | ||
function getTargetSize(vNode, minSize) { | ||
const nodeRect = vNode.boundingClientRect; | ||
const overlappingVNodes = findNearbyElms(vNode).filter(vNeighbor => { | ||
return ( | ||
vNeighbor.getComputedStylePropertyValue('pointer-events') !== 'none' && | ||
hasVisualOverlap(vNode, vNeighbor) | ||
); | ||
}); | ||
|
||
if (!overlappingVNodes.length) { | ||
return nodeRect; | ||
} | ||
|
||
return getLargestUnobscuredArea(vNode, overlappingVNodes, minSize); | ||
} | ||
|
||
// Find areas of the target that are not obscured | ||
function getLargestUnobscuredArea(vNode, obscuredNodes, minSize) { | ||
const nodeRect = vNode.boundingClientRect; | ||
if (obscuredNodes.length === 0) { | ||
return null; | ||
} | ||
const obscuringRects = obscuredNodes.map( | ||
({ boundingClientRect: rect }) => rect | ||
); | ||
const unobscuredRects = splitRects(nodeRect, obscuringRects); | ||
if (!unobscuredRects.length) { | ||
return null; | ||
} | ||
|
||
// Of the unobscured inner rects, work out the largest | ||
return getLargestRect(unobscuredRects, minSize); | ||
} | ||
|
||
// Find the largest rectangle in the array, prioritize ones that meet a minimum size | ||
function getLargestRect(rects, minSize) { | ||
return rects.reduce((rectA, rectB) => { | ||
const rectAisMinimum = rectHasMinimumSize(minSize, rectA); | ||
const rectBisMinimum = rectHasMinimumSize(minSize, rectB); | ||
// Prioritize rects that pass the minimum | ||
if (rectAisMinimum !== rectBisMinimum) { | ||
return rectAisMinimum ? rectA : rectB; | ||
} | ||
const areaA = rectA.width * rectA.height; | ||
const areaB = rectB.width * rectB.height; | ||
return areaA > areaB ? rectA : rectB; | ||
}); | ||
} | ||
|
||
function rectHasMinimumSize(minSize, { width, height }) { | ||
return ( | ||
width + roundingMargin >= minSize && height + roundingMargin >= minSize | ||
); | ||
} |
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
* @memberof axe.commons.math | ||
* @param {DOMRect} outerRect | ||
* @param {DOMRect[]} overlapRects | ||
* @returns {Rect[]} Unique array of rects | ||
* @returns {DOMRect[]} Unique array of rects | ||
*/ | ||
export default function splitRects(outerRect, overlapRects) { | ||
let uniqueRects = [outerRect]; | ||
|
@@ -37,19 +37,33 @@ function splitRect(inputRect, clipRect) { | |
rects.push({ top, left, bottom, right: clipRect.left }); | ||
} | ||
if (rects.length === 0) { | ||
// Fully overlapping | ||
if (isEnclosedRect(inputRect, clipRect)) { | ||
return []; | ||
} | ||
|
||
rects.push(inputRect); // No intersection | ||
} | ||
|
||
return rects.map(computeRect); // add x / y / width / height | ||
} | ||
|
||
const between = (num, min, max) => num > min && num < max; | ||
|
||
function computeRect(baseRect) { | ||
return { | ||
...baseRect, | ||
x: baseRect.left, | ||
y: baseRect.top, | ||
height: baseRect.bottom - baseRect.top, | ||
width: baseRect.right - baseRect.left | ||
}; | ||
return new window.DOMRect( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought it was weird that split rects works on DOMRects but then doesn't return one, which meant that doing |
||
baseRect.left, | ||
baseRect.top, | ||
baseRect.right - baseRect.left, | ||
baseRect.bottom - baseRect.top | ||
); | ||
} | ||
|
||
function isEnclosedRect(rectA, rectB) { | ||
return ( | ||
rectA.top >= rectB.top && | ||
rectA.left >= rectB.left && | ||
rectA.bottom <= rectB.bottom && | ||
rectA.right <= rectB.right | ||
); | ||
} |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function exists in IE11 (I've verified)