Skip to content

Commit 27a8d87

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 97197fd commit 27a8d87

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
@@ -283,6 +283,21 @@ class A11yValidator {
283283
);
284284
}
285285

286+
private checkInitialFocusNotCloseButton(dialogElement: HTMLElement): number {
287+
const active = document.activeElement;
288+
if (!active || !dialogElement.contains(active)) return 0;
289+
290+
if (active.classList.contains('ui-dialog-titlebar-close')) {
291+
console.error(
292+
new A11yValidatorException(
293+
`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.`,
294+
),
295+
);
296+
return 1;
297+
}
298+
return 0;
299+
}
300+
286301
private checkDuplicateButtonLabels(container: HTMLElement): number {
287302
const buttons = container.querySelectorAll('button[aria-labelledby]');
288303
const labelMap = new Map<string, HTMLElement[]>();
@@ -398,10 +413,11 @@ class A11yValidator {
398413
validateDialog(dialogElement: HTMLElement): void {
399414
const content = dialogElement.querySelector('.ui-dialog-content');
400415

401-
const errorCount = this.validateContainer(
402-
dialogElement,
403-
content instanceof HTMLElement ? content : undefined,
404-
);
416+
const errorCount =
417+
this.validateContainer(
418+
dialogElement,
419+
content instanceof HTMLElement ? content : undefined,
420+
) + this.checkInitialFocusNotCloseButton(dialogElement);
405421

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

0 commit comments

Comments
 (0)