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

Remove auto-focus on selected tab on page load #12406

Merged
merged 4 commits into from
Jan 11, 2023
Merged
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
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