I am using aurelia-dialog and I was hoping there is a setting to maintain focus within the dialog when it is open to meet accessibility requirements. I saw issue #375 which seems to say this has been addressed with issue #338 but I am not having any luck.
Reading through #338, I tried to to use the NativeDialogRenderer noted in the issue but I am getting an error “Uncaught Error: DialogRenderer must implement getDialogContainer()” when trying to display the dialog in the browser.
I may not be implementing things correctly. I am using version 2.0.0-rc.6 and here is what I have going on in main.js
import '@babel/polyfill';
import environment from './environment';
import {PLATFORM} from 'aurelia-pal';
import * as Bluebird from 'bluebird';
import { NativeDialogRenderer } from 'aurelia-dialog';
Bluebird.config({ warnings: { wForgottenReturn: false } });
export function configure(aurelia) {
aurelia.use
.standardConfiguration()
.feature(PLATFORM.moduleName('lib/index'))
.plugin(PLATFORM.moduleName('aurelia-animator-css'))
.plugin(PLATFORM.moduleName('aurelia-dialog'), config => {
config.settings.startingZIndex = 5;
config.settings.keyboard = true;
config.useDefaults();
config.useCSS('');
config.settings.centerHorizontalOnly = true;
config.useResource('attach-focus');
config.useRenderer(NativeDialogRenderer);
});
aurelia.use.developmentLogging(environment.debug ? 'debug' : 'warn');
if (environment.testing) {
aurelia.use.plugin(PLATFORM.moduleName('aurelia-testing'));
}
return aurelia.start().then(() => aurelia.setRoot(PLATFORM.moduleName('app')));
}
Or maybe the focus management has not been implemented?
Thanks,
Wendee
I am using “aurelia-dialog”: “^2.0.0”
Not sure how to change dialog to ensure that focus will remain in the dialog?
Do I need to switch to native renderer?
Do I need to use ‘attach-focus’ on elements? Thanks
Can you clarify what you meant with “remain focus in the dialog”? Is it when you open or when you close a dialog? If you want to move the focus to some element when opening the dialog, attach-focus is the one.
I think what he means is a restriction so that users can’t “tab” out of the dialog, focus should keep cycling between components inside the dialog while the dialog is active.
If you use aurelia-dialog with the NativeDialogRenderer it uses the HTML <dialog> element which handles focus automatically. This can be polyfilled for browsers that don’t support it (why Safari, why? ).
Firefox also did not turn on native dialog by default.
BTW, I have been working on a tiny cut-off version of aurelia-dialog called aurelia-dialog-lite.
How tiny? 250 LOC vs 1000+.
It got focus-trap out of the box without using native dialog element, also simplified css and layout so users can control that aspect. I have migrated all my apps to it. For a reference open-sourced app, check out the source code of dumber-gist IDE.
But the APIs are not compatible with aurelia-dialog. Don’t migrate if you are not sure.
The doc (the readme file) is only half done. But I have no plan to introduce more breaking changes.
I will definately check this out. I created a wrapper around aurelia-dialog to do what I want. It might be time to abandon aurelia-dialog completely with either your approach or something home grown.
It is quite easy to roll your own dialog implementation and trap focus manually but we should really be striving for something that excels on the accessibility front too.
As far as I understand it, the <dialog>element gets special treatment from screen readers.