Skip to content

Commit

Permalink
Added Tabindex to checks #7
Browse files Browse the repository at this point in the history
  • Loading branch information
Max van der Schee committed Jan 8, 2019
1 parent d53069e commit 5dfa182
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
15 changes: 13 additions & 2 deletions server/src/Patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const patterns: string[] = [
"<img(?:.)+?>",
"<input(?:.)+?>",
"<head(?:.|)+?>(?:(?:\\s|\\S|)+?(?=<\/head>))<\/head>",
"<html(?:.)+?>"
"<html(?:.)+?>",
"tabindex=\"(?:.)+?\""
];
export const pattern: RegExp = new RegExp(patterns.join('|'), 'ig');

Expand Down Expand Up @@ -205,7 +206,7 @@ export async function validateInput(m: RegExpExecArray) {
} else {
return {
meta: m,
mess: 'Provide an id with in the aria labelled by [aria-labelledby=""]'
mess: 'Provide an id with in the aria labelledby [aria-labelledby=""]'
};
}
case (/role=/i.test(m[0])):
Expand All @@ -217,4 +218,14 @@ export async function validateInput(m: RegExpExecArray) {
mess: 'Provide an aria label [aria-label=""]'
};
}
}

export async function validateTab(m: RegExpExecArray) {
connection.console.log(m[0]);
if (!/tabindex="(?:0|-1)"/i.test(m[0])) {
return {
meta: m,
mess: 'A tabindex greater than 0 interferes with the focus order. Try restructuring the HTML'
};
}
}
8 changes: 8 additions & 0 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ async function validateTextDocument(textDocument: TextDocument): Promise<void> {
_diagnostics(resultHtml.meta, resultHtml.mess);
}
break;
// Tabindex
case (/tabin/i.test(el)):
let resultTab = await Pattern.validateTab(m);
if (resultTab) {
problems++;
_diagnostics(resultTab.meta, resultTab.mess);
}
break;
default:
break;
}
Expand Down

0 comments on commit 5dfa182

Please sign in to comment.