Skip to content

Commit

Permalink
Only create tab keys if we have a tab bar renderer.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasongrout authored and telamonian committed Nov 17, 2020
1 parent 77a8017 commit a6fdb77
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
11 changes: 7 additions & 4 deletions packages/widgets/src/docklayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1994,14 +1994,17 @@ namespace Private {
}

export
async function addAria(widget: Widget, tabBar: TabBar<Widget>) {
let tabId = tabBar.renderer.createTabKey({title: widget.title, current: false, zIndex: 0});
function addAria(widget: Widget, tabBar: TabBar<Widget>) {
widget.node.setAttribute('role', 'tabpanel');
widget.node.setAttribute('aria-labelledby', tabId);
let renderer = tabBar.renderer;
if (renderer instanceof TabBar.Renderer) {
let tabId = renderer.createTabKey({ title: widget.title, current: false, zIndex: 0 });
widget.node.setAttribute('aria-labelledby', tabId);
}
}

export
async function removeAria(widget: Widget) {
function removeAria(widget: Widget) {
widget.node.removeAttribute('role');
widget.node.removeAttribute('aria-labelledby');
}
Expand Down
13 changes: 0 additions & 13 deletions packages/widgets/src/tabbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1434,19 +1434,6 @@ namespace TabBar {
* @returns A virtual element representing the tab.
*/
renderTab(data: IRenderData<T>): VirtualElement;

/**
* Create a stable unique id for a tab based on the title.
*
* @param data - The data to use for the tab.
*
* @returns The unique id for a tab.
*
* #### Notes
* This method returns a stable unique id for a tab, depending only on the
* title. The tab DOM `id` is set to this value.
*/
createTabKey(data: IRenderData<T>): string;
}

/**
Expand Down
8 changes: 6 additions & 2 deletions packages/widgets/src/tabpanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,13 @@ class TabPanel extends Widget {
this.stackedPanel.insertWidget(index, widget);
this.tabBar.insertTab(index, widget.title);

let tabId = this.tabBar.renderer.createTabKey({title: widget.title, current: false, zIndex: 0});
widget.node.setAttribute('role', 'tabpanel');
widget.node.setAttribute('aria-labelledby', tabId);

let renderer = this.tabBar.renderer
if (renderer instanceof TabBar.Renderer) {
let tabId = renderer.createTabKey({title: widget.title, current: false, zIndex: 0});
widget.node.setAttribute('aria-labelledby', tabId);
}
}

/**
Expand Down

0 comments on commit a6fdb77

Please sign in to comment.