Skip to content

Commit 9e412dd

Browse files
Display notice instead of header for tables with complex header structures
1 parent c3e3c19 commit 9e412dd

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

Diff for: HTMLCS.Util.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,8 @@ _global.HTMLCS.util = function() {
903903
* - wrongHeaders (Array): Array of elements where headers attr is incorrect.
904904
* Each is a structure with following keys: element,
905905
* expected [headers attr], actual [headers attr].
906+
* - isMultiLevelHeadersTable (Boolean): Whether this table has multi-level headers.
907+
* See: https://www.w3.org/WAI/tutorials/tables/multi-level/
906908
*
907909
* @param {DOMNode} element Table element to test upon.
908910
*
@@ -917,7 +919,8 @@ _global.HTMLCS.util = function() {
917919
allowScope: true,
918920
missingThId: [],
919921
missingTd: [],
920-
wrongHeaders: []
922+
wrongHeaders: [],
923+
isMultiLevelHeadersTable: false,
921924
};
922925

923926
var rows = self.getChildrenForTable(element, 'tr');
@@ -1022,6 +1025,7 @@ _global.HTMLCS.util = function() {
10221025

10231026
if ((multiHeaders.rows > 1) || (multiHeaders.cols > 1)) {
10241027
retval.allowScope = false;
1028+
retval.isMultiLevelHeadersTable = true;
10251029
} else if ((retval.allowScope === true) && ((multiHeaders.rows === 0) || (multiHeaders.cols === 0))) {
10261030
// If only one column OR one row header.
10271031
retval.required = false;

Diff for: Standards/WCAG2AAA/Sniffs/Principle1/Guideline1_3/1_3_1.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,13 @@ _global.HTMLCS_WCAG2AAA_Sniffs_Principle1_Guideline1_3_1_3_1 = {
459459
}
460460
}//end if
461461

462-
// Incorrect usage of headers - error; emit always.
463-
for (var i = 0; i < headersAttr.wrongHeaders.length; i++) {
464-
HTMLCS.addMessage(HTMLCS.ERROR, headersAttr.wrongHeaders[i].element, _global.HTMLCS.getTranslation("1_3_1_H43.IncorrectAttr").replace(/\{\{expected\}\}/g, headersAttr.wrongHeaders[i].expected).replace(/\{\{actual\}\}/g, headersAttr.wrongHeaders[i].actual), 'H43.IncorrectAttr');
462+
if (headersAttr.isMultiLevelHeadersTable) {
463+
HTMLCS.addMessage(HTMLCS.NOTICE, table, _global.HTMLCS.getTranslation("1_3_1_H43.IncorrectAttrNotice"), 'H43.IncorrectAttr');
464+
} else {
465+
// Incorrect usage of headers - error; emit always.
466+
for (var i = 0; i < headersAttr.wrongHeaders.length; i++) {
467+
HTMLCS.addMessage(HTMLCS.ERROR, headersAttr.wrongHeaders[i].element, _global.HTMLCS.getTranslation("1_3_1_H43.IncorrectAttr").replace(/\{\{expected\}\}/g, headersAttr.wrongHeaders[i].expected).replace(/\{\{actual\}\}/g, headersAttr.wrongHeaders[i].actual), 'H43.IncorrectAttr');
468+
}
465469
}
466470

467471
// Errors where headers are compulsory.

Diff for: Translations/en.js

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ _global.translation['en'] = {
121121
,"1_3_1_H63.2" : 'Scope attributes on td elements that act as headings for other elements are obsolete in HTML5. Use a th element instead.'
122122
,"1_3_1_H43.ScopeAmbiguous" : 'Scope attributes on th elements are ambiguous in a table with multiple levels of headings. Use the headers attribute on td elements instead.'
123123
,"1_3_1_H43.IncorrectAttr" : 'Incorrect headers attribute on this td element. Expected "{{expected}}" but found "{{actual}}"'
124+
,"1_3_1_H43.IncorrectAttrNotice" : 'Check that headers attribute on td element is correct.'
124125

125126
,"1_3_1_H43.HeadersRequired" : 'The relationship between td elements and their associated th elements is not defined. As this table has multiple levels of th elements, you must use the headers attribute on td elements.'
126127
,"1_3_1_H43.MissingHeaderIds" : 'Not all th elements in this table contain an id attribute. These cells should contain ids so that they may be referenced by td elements\' headers attributes.'

0 commit comments

Comments
 (0)