I am attempting to force a screen reader in Ionic 5 to focus on and announce an element.
My template element:
<ion-title tabindex="-1" #title id="title" role="heading" aria-level="1" class="title">My Title</ion-title>
I have attempted to access the element via document and as a Viewchild:
@ViewChild('title', { read: ElementRef }) title: ElementRef;
const title: any = document.getElementById('title');
I attempt to focus after a delay with this test:
ionViewWillEnter(): void {
setTimeout(() => {
const title: any = document.getElementById('title');
if (title) {
title.focus();
}
}, 3000);
setTimeout(() => {
this.title.nativeElement.focus();
}, 5000);
}
Neither of these focus, however. The screen reader does not announce the title in either Android nor iOS.
Update
Just to clarify, I need the screen reader position to move to a specified element. Focusing on an element as described will not move the screen reader position.
Any help would be appreciated, here's my Ionic info:
Ionic CLI : 5.4.16
Ionic Framework : @ionic/angular 5.5.3
@angular-devkit/build-angular : 0.901.15
@angular-devkit/schematics : 9.1.15
@angular/cli : 9.1.15
@ionic/angular-toolkit : 2.3.3
Capacitor:
Capacitor CLI : 2.4.2
@capacitor/core : 2.4.0