is-data-cell.js 676 B

123456789101112131415161718192021222324
  1. import isValidRole from '../aria/is-valid-role';
  2. /**
  3. * Determine if a `HTMLTableCellElement` is a data cell
  4. * @method isDataCell
  5. * @memberof axe.commons.table
  6. * @instance
  7. * @param {HTMLTableCellElement} node The table cell to test
  8. * @return {Boolean}
  9. */
  10. function isDataCell(cell) {
  11. // @see http://www.whatwg.org/specs/web-apps/current-work/multipage/tables.html#empty-cell
  12. if (!cell.children.length && !cell.textContent.trim()) {
  13. return false;
  14. }
  15. const role = cell.getAttribute('role');
  16. if (isValidRole(role)) {
  17. return ['cell', 'gridcell'].includes(role);
  18. } else {
  19. return cell.nodeName.toUpperCase() === 'TD';
  20. }
  21. }
  22. export default isDataCell;