-
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(color-contrast): account for elements that do not fill entire bounding size #3186
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -360,6 +360,8 @@ function addNodeToGrid(grid, vNode) { | |
const endRow = ((y + rect.height) / gridSize) | 0; | ||
const endCol = ((x + rect.width) / gridSize) | 0; | ||
|
||
grid._numCols = Math.max(grid._numCols ?? 0, endCol); | ||
|
||
for (let row = startRow; row <= endRow; row++) { | ||
grid.cells[row] = grid.cells[row] || []; | ||
|
||
|
@@ -475,21 +477,34 @@ export function getRectStack(grid, rect, recursed = false) { | |
// went with pixel perfect collision rather than rounding | ||
const row = (y / gridSize) | 0; | ||
const col = (x / gridSize) | 0; | ||
let stack = grid.cells[row][col].filter(gridCellNode => { | ||
return gridCellNode.clientRects.find(clientRect => { | ||
const rectX = clientRect.left; | ||
const rectY = clientRect.top; | ||
|
||
// perform an AABB (axis-aligned bounding box) collision check for the | ||
// point inside the rect | ||
return ( | ||
x <= rectX + clientRect.width && | ||
x >= rectX && | ||
y <= rectY + clientRect.height && | ||
y >= rectY | ||
); | ||
}); | ||
}); | ||
|
||
// we're making an assumption that there cannot be an element in the | ||
// grid which escapes the grid bounds. For example, if the grid is 4x4 there | ||
// can't be an element whose midpoint is at column 5. If this happens this | ||
// means there's an error in our grid logic that needs to be fixed | ||
if (row > grid.cells.length || col > grid._numCols) { | ||
straker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
throw new Error('Element midpoint exceeds the grid bounds'); | ||
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 don't follow why you would want this to throw. Crashing axe-core doesn't seem like the right solution here. 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. Because I want to know when our custom grid logic fails, and it shows there's an issue that needs to be fixed. Without throwing, color contrast would hide issues that should be fixed. |
||
} | ||
|
||
// it is acceptable if a row has empty cells due to client rects not filling | ||
// the entire bounding rect of an element | ||
// @see https://github.com/dequelabs/axe-core/issues/3166 | ||
let stack = | ||
grid.cells[row][col]?.filter(gridCellNode => { | ||
return gridCellNode.clientRects.find(clientRect => { | ||
const rectX = clientRect.left; | ||
const rectY = clientRect.top; | ||
|
||
// perform an AABB (axis-aligned bounding box) collision check for the | ||
// point inside the rect | ||
return ( | ||
x <= rectX + clientRect.width && | ||
x >= rectX && | ||
y <= rectY + clientRect.height && | ||
y >= rectY | ||
); | ||
}); | ||
}) ?? []; | ||
|
||
const gridContainer = grid.container; | ||
if (gridContainer) { | ||
|
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 feels a little off. If
_numCols
needs to be different, it should be fixed where that value is set. If it doesn't need to be changed, this should probably just be a local variable.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.
It needs to be set for every grid, so can't be local. Grid items are added dynamically, so there's no way to know how many rows or columns the grid will have before hand, we can only know as each item is added and changes the grid size.