Sha256: 1ed6390ef58c9955c011627b20a567dff86b808f30e46675be791d5fc81dee23

Contents?: true

Size: 1.87 KB

Versions: 104

Compression:

Stored size: 1.87 KB

Contents

var tableUtils = axe.commons.table;
var cells = tableUtils.getAllCells(node);
var checkResult = this;

// Get a list of all headers reffed to in this rule
var reffedHeaders = [];
cells.forEach(function(cell) {
	var headers = cell.getAttribute('headers');
	if (headers) {
		reffedHeaders = reffedHeaders.concat(headers.split(/\s+/));
	}

	var ariaLabel = cell.getAttribute('aria-labelledby');
	if (ariaLabel) {
		reffedHeaders = reffedHeaders.concat(ariaLabel.split(/\s+/));
	}
});

// Get all the headers
var headers = cells.filter(function(cell) {
	if (axe.commons.text.sanitize(cell.textContent) === '') {
		return false;
	}
	return (
		cell.nodeName.toUpperCase() === 'TH' ||
		['rowheader', 'columnheader'].indexOf(cell.getAttribute('role')) !== -1
	);
});

var tableGrid = tableUtils.toGrid(node);

// Look for all the bad headers
var out = headers.reduce(function(res, header) {
	if (
		header.getAttribute('id') &&
		reffedHeaders.includes(header.getAttribute('id'))
	) {
		return !res ? res : true;
	}

	var hasCell = false;
	var pos = tableUtils.getCellPosition(header, tableGrid);

	// Look for any data cells or row headers that this might refer to
	if (tableUtils.isColumnHeader(header)) {
		hasCell = tableUtils
			.traverse('down', pos, tableGrid)
			.reduce((out, cell) => {
				return (
					out ||
					(axe.commons.dom.hasContent(cell) && !tableUtils.isColumnHeader(cell))
				);
			}, false);
	}

	// Look for any data cells or column headers that this might refer to
	if (!hasCell && tableUtils.isRowHeader(header)) {
		hasCell = tableUtils
			.traverse('right', pos, tableGrid)
			.reduce((out, cell) => {
				return (
					out ||
					(axe.commons.dom.hasContent(cell) && !tableUtils.isRowHeader(cell))
				);
			}, false);
	}

	// report the node as having failed
	if (!hasCell) {
		checkResult.relatedNodes(header);
	}

	return res && hasCell;
}, true);

return out ? true : undefined;

Version data entries

104 entries across 104 versions & 1 rubygems

Version Path
govuk_publishing_components-21.16.3 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.16.2 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.16.1 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.16.0 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.15.2 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.15.1 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.15.0 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.14.0 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.13.5 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.13.4 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.13.3 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.13.2 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.13.1 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.13.0 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.12.0 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.11.0 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.10.0 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.9.0 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.8.1 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.8.0 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js