Skip to content

Commit 902cf49

Browse files
committed
add cypress to fail if initial focus is on 'X'
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com> Change-Id: Ia89aafd6fc2af1dc9567f4d7d945663384a8f232
1 parent 182afdb commit 902cf49

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

browser/src/app/A11yValidator.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,21 @@ class A11yValidator {
248248
}
249249
}
250250

251+
private checkInitialFocusNotCloseButton(dialogElement: HTMLElement): number {
252+
const active = document.activeElement;
253+
if (!active || !dialogElement.contains(active)) return 0;
254+
255+
if (active.classList.contains('ui-dialog-titlebar-close')) {
256+
console.error(
257+
new A11yValidatorException(
258+
`In '${this.getDialogTitle(active as HTMLElement)}': initial keyboard focus is on the close (X) button in the titlebar. Focus should be on a control inside the dialog body.`,
259+
),
260+
);
261+
return 1;
262+
}
263+
return 0;
264+
}
265+
251266
private checkDuplicateButtonLabels(container: HTMLElement): number {
252267
const buttons = container.querySelectorAll('button[aria-labelledby]');
253268
const labelMap = new Map<string, HTMLElement[]>();
@@ -363,10 +378,11 @@ class A11yValidator {
363378
validateDialog(dialogElement: HTMLElement): void {
364379
const content = dialogElement.querySelector('.ui-dialog-content');
365380

366-
const errorCount = this.validateContainer(
367-
dialogElement,
368-
content instanceof HTMLElement ? content : undefined,
369-
);
381+
const errorCount =
382+
this.validateContainer(
383+
dialogElement,
384+
content instanceof HTMLElement ? content : undefined,
385+
) + this.checkInitialFocusNotCloseButton(dialogElement);
370386

371387
if (errorCount === 0) {
372388
console.error('A11yValidator: dialog passed all checks');

0 commit comments

Comments
 (0)