td-has-header-evaluate.js 911 B

123456789101112131415161718192021222324252627282930313233
  1. import * as tableUtils from '../../commons/table';
  2. import { hasContent } from '../../commons/dom';
  3. import { label } from '../../commons/aria';
  4. function tdHasHeaderEvaluate(node) {
  5. const badCells = [];
  6. const cells = tableUtils.getAllCells(node);
  7. const tableGrid = tableUtils.toGrid(node);
  8. cells.forEach(cell => {
  9. // For each non-empty data cell that doesn't have an aria label
  10. if (hasContent(cell) && tableUtils.isDataCell(cell) && !label(cell)) {
  11. // Check if it has any headers
  12. const hasHeaders = tableUtils.getHeaders(cell, tableGrid).some(header => {
  13. return header !== null && !!hasContent(header);
  14. });
  15. // If no headers, put it on the naughty list
  16. if (!hasHeaders) {
  17. badCells.push(cell);
  18. }
  19. }
  20. });
  21. if (badCells.length) {
  22. this.relatedNodes(badCells);
  23. return false;
  24. }
  25. return true;
  26. }
  27. export default tdHasHeaderEvaluate;