Skip to content

Commit 4dcbf55

Browse files
committed
Fixed accessibility issue with widget selection announcement.
1 parent eebbc16 commit 4dcbf55

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

src/core.design.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ import { ContentPart } from "./content-part/ko";
110110
import { UrlDesignModule } from "./workshops/urls/ko/url.design.module";
111111
import { PopupDesignModule } from "./popup/popup.design.module";
112112
import { ContainerEditorModule } from "./container/container.design.module";
113+
import { LiveAreaBindingHandler } from "./ko/bindingHandlers/bindingHandlers.livearea";
113114

114115

115116
export class CoreDesignModule implements IInjectorModule {
@@ -265,6 +266,7 @@ export class CoreDesignModule implements IInjectorModule {
265266
injector.bindToCollection("autostart", Hinter);
266267
injector.bindToCollection("autostart", WidgetBindingHandler);
267268
injector.bindToCollection("autostart", BackgroundBindingHandler);
269+
injector.bindToCollection("autostart", LiveAreaBindingHandler);
268270

269271
injector.bindInstance("reservedPermalinks", ["/", "/404", "/500"]);
270272
injector.resolve("workshopSections");

src/grid/ko/gridEditor.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class GridEditor {
2929
private ownerDocument: Document;
3030
private selection: GridItem;
3131
private activeLayer: string;
32+
private noificationTimeout: any;
3233

3334
constructor(
3435
private readonly viewManager: ViewManager,
@@ -386,6 +387,17 @@ export class GridEditor {
386387
throw new Error(`Parameter "item" not specified.`);
387388
}
388389

390+
this.eventManager.dispatchEvent(Events.NotificationRequest, item.displayName);
391+
392+
if (this.noificationTimeout) {
393+
clearTimeout(this.noificationTimeout);
394+
}
395+
396+
this.noificationTimeout = setTimeout(() => {
397+
this.eventManager.dispatchEvent(Events.NotificationRequest, "selected");
398+
}, 1000);
399+
400+
389401
const commandSet = item?.getContextCommands();
390402

391403
if (!commandSet) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { EventManager, Events } from "@paperbits/common/events";
2+
import * as ko from "knockout";
3+
4+
5+
export class LiveAreaBindingHandler {
6+
constructor(eventManager: EventManager) {
7+
ko.bindingHandlers["livearea"] = {
8+
init: (element: HTMLElement, valueAccessor: () => (data: unknown) => void, allBindings, viewModel) => {
9+
const notificationHandler = (notification: string) => {
10+
element.innerText = notification;
11+
}
12+
13+
eventManager.addEventListener(Events.NotificationRequest, notificationHandler);
14+
15+
ko.utils.domNodeDisposal.addDisposeCallback(element, () => {
16+
eventManager.removeEventListener(Events.NotificationRequest, notificationHandler);
17+
})
18+
}
19+
};
20+
}
21+
}
22+

src/ko/ui/defaultViewManager.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<!-- ko if: host -->
2+
<div aria-live="assertive" data-bind="livearea: {}"></div>
23
<div id="contentEditor" class="viewport" tabindex="0"
34
data-bind="host: { viewport: viewport, host: host, block: block, onDocumentCreated: onHostDocumentCreated, onDocumentDisposed: onHostDocumentDisposed }"></div>
45
<!-- /ko -->

0 commit comments

Comments
 (0)