Commit 2376bfbe authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Add aria-controls and remove aria-pressed in sidebar toggle

parent 665bc25d
...@@ -72,6 +72,12 @@ export type ToolbarProps = { ...@@ -72,6 +72,12 @@ export type ToolbarProps = {
/** Is the sidebar currently open? */ /** Is the sidebar currently open? */
isSidebarOpen: boolean; isSidebarOpen: boolean;
/**
* The id attribute for the sidebar container to reference from the sidebar
* toggle's aria-controls attribute
*/
sidebarContainerId?: string;
/** /**
* Informs which icon to show on the "Create annotation" button and what type * Informs which icon to show on the "Create annotation" button and what type
* of annotation should be created by the `createAnnotation` callback. The * of annotation should be created by the `createAnnotation` callback. The
...@@ -117,6 +123,7 @@ export default function Toolbar({ ...@@ -117,6 +123,7 @@ export default function Toolbar({
closeSidebar, closeSidebar,
createAnnotation, createAnnotation,
isSidebarOpen, isSidebarOpen,
sidebarContainerId,
newAnnotationType, newAnnotationType,
showHighlights, showHighlights,
toggleHighlights, toggleHighlights,
...@@ -171,7 +178,7 @@ export default function Toolbar({ ...@@ -171,7 +178,7 @@ export default function Toolbar({
elementRef={toggleSidebarRef} elementRef={toggleSidebarRef}
title="Annotation sidebar" title="Annotation sidebar"
expanded={isSidebarOpen} expanded={isSidebarOpen}
pressed={isSidebarOpen} aria-controls={sidebarContainerId}
onClick={toggleSidebar} onClick={toggleSidebar}
unstyled unstyled
> >
......
...@@ -100,6 +100,15 @@ describe('Toolbar', () => { ...@@ -100,6 +100,15 @@ describe('Toolbar', () => {
}); });
}); });
it('sets aria-controls in sidebar toggle button', () => {
const wrapper = createToolbar({ sidebarContainerId: 'foo' });
assert.equal(
findButton(wrapper, 'Annotation sidebar').prop('aria-controls'),
'foo',
);
});
it( it(
'should pass a11y checks', 'should pass a11y checks',
checkAccessibility([ checkAccessibility([
......
...@@ -174,6 +174,7 @@ export class Sidebar implements Destroyable { ...@@ -174,6 +174,7 @@ export class Sidebar implements Destroyable {
this.iframeContainer = document.createElement('div'); this.iframeContainer = document.createElement('div');
this.iframeContainer.style.display = 'none'; this.iframeContainer.style.display = 'none';
this.iframeContainer.className = 'sidebar-container'; this.iframeContainer.className = 'sidebar-container';
this.iframeContainer.id = 'sidebar-container';
if (config.theme === 'clean') { if (config.theme === 'clean') {
this.iframeContainer.classList.add('theme-clean'); this.iframeContainer.classList.add('theme-clean');
...@@ -260,6 +261,7 @@ export class Sidebar implements Destroyable { ...@@ -260,6 +261,7 @@ export class Sidebar implements Destroyable {
// Set up the toolbar on the left edge of the sidebar. // Set up the toolbar on the left edge of the sidebar.
const toolbarContainer = document.createElement('div'); const toolbarContainer = document.createElement('div');
this.toolbar = new ToolbarController(toolbarContainer, { this.toolbar = new ToolbarController(toolbarContainer, {
sidebarContainerId: this.iframeContainer?.id,
createAnnotation: () => { createAnnotation: () => {
if (this._guestRPC.length === 0) { if (this._guestRPC.length === 0) {
return; return;
......
...@@ -7,6 +7,7 @@ export type ToolbarOptions = { ...@@ -7,6 +7,7 @@ export type ToolbarOptions = {
createAnnotation: () => void; createAnnotation: () => void;
setSidebarOpen: (open: boolean) => void; setSidebarOpen: (open: boolean) => void;
setHighlightsVisible: (visible: boolean) => void; setHighlightsVisible: (visible: boolean) => void;
sidebarContainerId?: string;
}; };
/** /**
...@@ -21,6 +22,7 @@ export class ToolbarController { ...@@ -21,6 +22,7 @@ export class ToolbarController {
private _useMinimalControls: boolean; private _useMinimalControls: boolean;
private _highlightsVisible: boolean; private _highlightsVisible: boolean;
private _sidebarOpen: boolean; private _sidebarOpen: boolean;
private _sidebarContainerId?: string;
private _closeSidebar: () => void; private _closeSidebar: () => void;
private _toggleSidebar: () => void; private _toggleSidebar: () => void;
private _toggleHighlights: () => void; private _toggleHighlights: () => void;
...@@ -38,6 +40,7 @@ export class ToolbarController { ...@@ -38,6 +40,7 @@ export class ToolbarController {
this._newAnnotationType = 'note'; this._newAnnotationType = 'note';
this._highlightsVisible = false; this._highlightsVisible = false;
this._sidebarOpen = false; this._sidebarOpen = false;
this._sidebarContainerId = options.sidebarContainerId;
this._closeSidebar = () => setSidebarOpen(false); this._closeSidebar = () => setSidebarOpen(false);
this._toggleSidebar = () => setSidebarOpen(!this._sidebarOpen); this._toggleSidebar = () => setSidebarOpen(!this._sidebarOpen);
...@@ -124,6 +127,7 @@ export class ToolbarController { ...@@ -124,6 +127,7 @@ export class ToolbarController {
createAnnotation={this._createAnnotation} createAnnotation={this._createAnnotation}
newAnnotationType={this._newAnnotationType} newAnnotationType={this._newAnnotationType}
isSidebarOpen={this._sidebarOpen} isSidebarOpen={this._sidebarOpen}
sidebarContainerId={this._sidebarContainerId}
showHighlights={this._highlightsVisible} showHighlights={this._highlightsVisible}
toggleHighlights={this._toggleHighlights} toggleHighlights={this._toggleHighlights}
toggleSidebar={this._toggleSidebar} toggleSidebar={this._toggleSidebar}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment