Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a screen reader announcement with notification information when the panel is expanded #81

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@
margin: 0;
margin-top: 15px;
}

.aria-live-region {
position: absolute;
top: -9999px;
overflow: hidden;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
export const notificationsExplorer: string;
export const clearAllNotificationsBtn: string;
export const noNotificationsMsg: string;
export const ariaLiveRegion: string;
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ interface NotificationExplorerProps {
}

class NotificationsExplorerComp extends React.Component<NotificationExplorerProps, Record<string, unknown>> {
private spanNotificationRef: HTMLSpanElement;

constructor(props: NotificationExplorerProps) {
super(props);
}
Expand All @@ -56,6 +58,12 @@ class NotificationsExplorerComp extends React.Component<NotificationExplorerProp
const { notifications = [] } = this.props;
const clearAllButton = notifications.length ? this.renderClearAllButton() : null;

setTimeout(() => {
this.spanNotificationRef.innerText = notifications.length
? `${notifications.length} new notifications`
: 'No new notifications';
}, 500);

// max-height: 100% of explorer pane - 20px (Clear all button height) - 40px (Explorer title height)
return (
<>
Expand All @@ -70,6 +78,12 @@ class NotificationsExplorerComp extends React.Component<NotificationExplorerProp
<p className={styles.noNotificationsMsg}>No new notifications.</p>
)}
</ul>
<span
id="spanNotification"
aria-live={'polite'}
ref={this.setSpanNotificationRef}
className={styles.ariaLiveRegion}
/>
</>
);
}
Expand All @@ -81,6 +95,10 @@ class NotificationsExplorerComp extends React.Component<NotificationExplorerProp
</LinkButton>
);
};

private setSpanNotificationRef = (ref: HTMLSpanElement): void => {
this.spanNotificationRef = ref;
};
}

const mapStateToProps = (state: RootState): NotificationExplorerProps => {
Expand Down