Skip to content

Commit 118df25

Browse files
authoredNov 20, 2024
Website tabs - Set focus on tab change (#2561)
1 parent 69d62f4 commit 118df25

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed
 

‎website/app/components/doc/page/tabs.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
role="tab"
1515
aria-controls={{tab.target}}
1616
aria-selected={{if tab.isCurrent "true" "false"}}
17-
{{on "click" (fn tab.onClickTab tab)}}
17+
{{on "click" (fn this.onClickTab tab)}}
1818
>{{capitalize tab.label}}</button>
1919
</li>
2020
{{/each}}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Copyright (c) HashiCorp, Inc.
3+
* SPDX-License-Identifier: MPL-2.0
4+
*/
5+
6+
import Component from '@glimmer/component';
7+
import { action } from '@ember/object';
8+
9+
export default class DocPageTabsComponent extends Component {
10+
@action
11+
onClickTab(tab) {
12+
// Invoke the callback function if it's provided as argument
13+
if (typeof tab.onClickTab === 'function') {
14+
tab.onClickTab(tab);
15+
}
16+
17+
// Set focus on tab clicked
18+
let tabElement = document.getElementById(tab.id);
19+
tabElement.focus();
20+
}
21+
}

‎website/app/controllers/application.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,13 @@ export default class ApplicationController extends Controller {
100100
// Disable transition validation if we're transitioning to the same page
101101
// and the page is has a filter functionality based on `queryParams`
102102
// namely the Icon library or the Tokens page
103+
// or if the transition is between tabs on the same page
104+
let hasTabs = document.querySelector('.doc-page-tabs') != null;
103105
if (
104106
transition.from.params.path === transition.to.params.path &&
105107
(transition.from.params.path === 'icons/library' ||
106-
transition.from.params.path === 'foundations/tokens')
108+
transition.from.params.path === 'foundations/tokens' ||
109+
hasTabs)
107110
) {
108111
return false;
109112
} else {

‎website/app/controllers/show.js

-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ export default class ShowController extends Controller {
246246
}
247247

248248
// TABS
249-
// ?? CAN WE EXPLICITLY SET FOCUS ON THE TAB WHEN IT IS SET TO CURRENT?
250249
this.tabs.forEach((tab) => {
251250
set(tab, 'isCurrent', tab.index === current);
252251
});

0 commit comments

Comments
 (0)