Skip to content

Commit

Permalink
Merge pull request #12406 from craftcms/a11y/remove-tab-focus
Browse files Browse the repository at this point in the history
Remove auto-focus on selected tab on page load
  • Loading branch information
brandonkelly authored Jan 11, 2023
2 parents 7b95b8e + 8aeb45f commit c030351
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
- Improved keyboard control of the Updates utility. ([#12189](https://github.com/craftcms/cms/pull/12189))
- Improved the color contrast and keyboard control of the Customize Sources modal. ([#12233](https://github.com/craftcms/cms/pull/12233))
- Improved info icons for screen readers. ([#12272](https://github.com/craftcms/cms/pull/12272))
- Removed input autofocussing throughout the control panel. ([#12324](https://github.com/craftcms/cms/discussions/12324), [#12332](https://github.com/craftcms/cms/pull/12332))
- Removed input autofocussing throughout the control panel. ([#12324](https://github.com/craftcms/cms/discussions/12324), [#12332](https://github.com/craftcms/cms/pull/12332), [#12406](https://github.com/craftcms/cms/pull/12406))
- Improved the login screen for screen readers. ([#12386](https://github.com/craftcms/cms/pull/12386))

### Administration
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js.map

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions src/web/assets/cp/src/js/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ Craft.Tabs = Garnish.Base.extend({
this.addListener($a, 'keydown', (ev) => {
if ([Garnish.SPACE_KEY, Garnish.RETURN_KEY].includes(ev.keyCode)) {
ev.preventDefault();
this.selectTab(ev.currentTarget);
this.selectTab(ev.currentTarget, true);
}
});
this.addListener($a, 'click', (ev) => {
ev.preventDefault();
this.selectTab(ev.currentTarget);
this.selectTab(ev.currentTarget, true);
});
}

Expand Down Expand Up @@ -108,7 +108,7 @@ Craft.Tabs = Garnish.Base.extend({
});
},

selectTab: function (tab) {
selectTab: function (tab, focusTab = false) {
const $tab = this._getTab(tab);

if ($tab[0] === this.$selectedTab[0]) {
Expand All @@ -118,7 +118,11 @@ Craft.Tabs = Garnish.Base.extend({
this.deselectTab();
this.$selectedTab = $tab.addClass('sel').attr('aria-selected', 'true');
this.makeTabFocusable($tab);
$tab.focus();

if (focusTab) {
$tab.trigger('focus');
}

this.scrollToTab($tab);

this.menu.$options.removeClass('sel');
Expand Down

0 comments on commit c030351

Please sign in to comment.