Revert "A11Y: Switch tabs using the keyboard (#12241)" (#12260)

This reverts commit de10c39fa4.
This commit is contained in:
Roman Rizzi 2021-03-02 13:17:36 -03:00 committed by GitHub
parent de10c39fa4
commit 4c1e02d412
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 74 deletions

View File

@ -6,7 +6,6 @@ import PanEvents, {
import { cancel, later, schedule } from "@ember/runloop"; import { cancel, later, schedule } from "@ember/runloop";
import Docking from "discourse/mixins/docking"; import Docking from "discourse/mixins/docking";
import MountWidget from "discourse/components/mount-widget"; import MountWidget from "discourse/components/mount-widget";
import Mousetrap from "mousetrap";
import RerenderOnDoNotDisturbChange from "discourse/mixins/rerender-on-do-not-disturb-change"; import RerenderOnDoNotDisturbChange from "discourse/mixins/rerender-on-do-not-disturb-change";
import { observes } from "discourse-common/utils/decorators"; import { observes } from "discourse-common/utils/decorators";
import { topicTitleDecorators } from "discourse/components/topic-title"; import { topicTitleDecorators } from "discourse/components/topic-title";
@ -26,7 +25,6 @@ const SiteHeaderComponent = MountWidget.extend(
_scheduledMovingAnimation: null, _scheduledMovingAnimation: null,
_scheduledRemoveAnimate: null, _scheduledRemoveAnimate: null,
_topic: null, _topic: null,
_mousetrap: null,
@observes( @observes(
"currentUser.unread_notifications", "currentUser.unread_notifications",
@ -211,7 +209,6 @@ const SiteHeaderComponent = MountWidget.extend(
this.dispatch("notifications:changed", "user-notifications"); this.dispatch("notifications:changed", "user-notifications");
this.dispatch("header:keyboard-trigger", "header"); this.dispatch("header:keyboard-trigger", "header");
this.dispatch("search-autocomplete:after-complete", "search-term"); this.dispatch("search-autocomplete:after-complete", "search-term");
this.dispatch("user-menu:navigation", "user-menu");
this.appEvents.on("dom:clean", this, "_cleanDom"); this.appEvents.on("dom:clean", this, "_cleanDom");
@ -239,26 +236,6 @@ const SiteHeaderComponent = MountWidget.extend(
once: true, once: true,
}); });
} }
const header = document.querySelector("header.d-header");
const mousetrap = new Mousetrap(header);
mousetrap.bind(["right", "left"], (e) => {
const activeTab = document.querySelector(".glyphs .menu-link.active");
if (activeTab) {
let focusedTab = document.activeElement;
if (!focusedTab.dataset.tabNumber) {
focusedTab = activeTab;
}
this.appEvents.trigger("user-menu:navigation", {
key: e.key,
tabNumber: Number(focusedTab.dataset.tabNumber),
});
}
});
this.set("_mousetrap", mousetrap);
}, },
_cleanDom() { _cleanDom() {
@ -280,8 +257,6 @@ const SiteHeaderComponent = MountWidget.extend(
cancel(this._scheduledRemoveAnimate); cancel(this._scheduledRemoveAnimate);
window.cancelAnimationFrame(this._scheduledMovingAnimation); window.cancelAnimationFrame(this._scheduledMovingAnimation);
this._mousetrap.unbind(["right", "left"]);
document.removeEventListener("click", this._dismissFirstNotification); document.removeEventListener("click", this._dismissFirstNotification);
}, },

View File

@ -28,10 +28,6 @@ export const ButtonClass = {
return className; return className;
}, },
buildId(attrs) {
return attrs.id;
},
buildAttributes() { buildAttributes() {
const attrs = this.attrs; const attrs = this.attrs;
const attributes = {}; const attributes = {};
@ -74,7 +70,7 @@ export const ButtonClass = {
const icon = iconNode(attrs.icon, { class: attrs.iconClass }); const icon = iconNode(attrs.icon, { class: attrs.iconClass });
if (attrs["aria-label"]) { if (attrs["aria-label"]) {
icon.properties.attributes["role"] = "img"; icon.properties.attributes["role"] = "img";
icon.properties.attributes["aria-hidden"] = true; icon.properties.attributes["aria-hidden"] = false;
} }
return icon; return icon;
}, },

View File

@ -40,13 +40,9 @@ export default createWidget("quick-access-panel", {
return Promise.resolve([]); return Promise.resolve([]);
}, },
buildId() {
return this.key;
},
buildAttributes() { buildAttributes() {
const attributes = this.attrs; const attributes = this.attrs;
attributes["aria-labelledby"] = attributes.currentQuickAccess; attributes["aria-labelledby"] = this.key;
attributes["tabindex"] = "0"; attributes["tabindex"] = "0";
attributes["role"] = "tabpanel"; attributes["role"] = "tabpanel";

View File

@ -1,6 +1,6 @@
import { later } from "@ember/runloop";
import { createWidget } from "discourse/widgets/widget"; import { createWidget } from "discourse/widgets/widget";
import { h } from "virtual-dom"; import { h } from "virtual-dom";
import { later } from "@ember/runloop";
const UserMenuAction = { const UserMenuAction = {
QUICK_ACCESS: "quickAccess", QUICK_ACCESS: "quickAccess",
@ -59,8 +59,7 @@ createWidget("user-menu-links", {
profileGlyph() { profileGlyph() {
return { return {
title: Titles["profile"], title: Titles["profile"],
className: "user-preferences-link menu-link", className: "user-preferences-link",
id: QuickAccess.PROFILE,
icon: "user", icon: "user",
action: UserMenuAction.QUICK_ACCESS, action: UserMenuAction.QUICK_ACCESS,
actionParam: QuickAccess.PROFILE, actionParam: QuickAccess.PROFILE,
@ -73,8 +72,7 @@ createWidget("user-menu-links", {
notificationsGlyph() { notificationsGlyph() {
return { return {
title: Titles["notifications"], title: Titles["notifications"],
className: "user-notifications-link menu-link", className: "user-notifications-link",
id: QuickAccess.NOTIFICATIONS,
icon: "bell", icon: "bell",
action: UserMenuAction.QUICK_ACCESS, action: UserMenuAction.QUICK_ACCESS,
actionParam: QuickAccess.NOTIFICATIONS, actionParam: QuickAccess.NOTIFICATIONS,
@ -89,8 +87,7 @@ createWidget("user-menu-links", {
title: Titles["bookmarks"], title: Titles["bookmarks"],
action: UserMenuAction.QUICK_ACCESS, action: UserMenuAction.QUICK_ACCESS,
actionParam: QuickAccess.BOOKMARKS, actionParam: QuickAccess.BOOKMARKS,
className: "user-bookmarks-link menu-link", className: "user-bookmarks-link",
id: QuickAccess.BOOKMARKS,
icon: "bookmark", icon: "bookmark",
data: { url: `${this.attrs.path}/activity/bookmarks` }, data: { url: `${this.attrs.path}/activity/bookmarks` },
"aria-label": "user.bookmarks", "aria-label": "user.bookmarks",
@ -104,8 +101,7 @@ createWidget("user-menu-links", {
title: Titles["messages"], title: Titles["messages"],
action: UserMenuAction.QUICK_ACCESS, action: UserMenuAction.QUICK_ACCESS,
actionParam: QuickAccess.MESSAGES, actionParam: QuickAccess.MESSAGES,
className: "user-pms-link menu-link", className: "user-pms-link",
id: QuickAccess.MESSAGES,
icon: "envelope", icon: "envelope",
data: { url: `${this.attrs.path}/messages` }, data: { url: `${this.attrs.path}/messages` },
role: "tab", role: "tab",
@ -120,12 +116,10 @@ createWidget("user-menu-links", {
return this.attach("link", link); return this.attach("link", link);
}, },
glyphHtml(glyph, idx) { glyphHtml(glyph) {
if (this.isActive(glyph)) { if (this.isActive(glyph)) {
glyph = this.markAsActive(glyph); glyph = this.markAsActive(glyph);
} }
glyph.data["tab-number"] = `${idx}`;
return this.attach("flat-button", glyph); return this.attach("flat-button", glyph);
}, },
@ -159,7 +153,7 @@ createWidget("user-menu-links", {
h( h(
"div.glyphs", "div.glyphs",
{ attributes: { "aria-label": "Menu links", role: "tablist" } }, { attributes: { "aria-label": "Menu links", role: "tablist" } },
glyphs.map((l, index) => this.glyphHtml(l, index)) glyphs.map((l) => this.glyphHtml(l))
), ),
]); ]);
}, },
@ -200,25 +194,6 @@ export default createWidget("user-menu", {
showLogoutButton: true, showLogoutButton: true,
}, },
userMenuNavigation(nav) {
const maxTabNumber = document.querySelectorAll(".glyphs button").length - 1;
const isLeft = nav.key === "ArrowLeft";
let nextTab = isLeft ? nav.tabNumber - 1 : nav.tabNumber + 1;
if (isLeft && nextTab < 0) {
nextTab = maxTabNumber;
}
if (!isLeft && nextTab > maxTabNumber) {
nextTab = 0;
}
document
.querySelector(`.menu-link[role='tab'][data-tab-number='${nextTab}']`)
.focus();
},
defaultState() { defaultState() {
return { return {
currentQuickAccess: QuickAccess.NOTIFICATIONS, currentQuickAccess: QuickAccess.NOTIFICATIONS,
@ -237,7 +212,7 @@ export default createWidget("user-menu", {
path, path,
currentQuickAccess, currentQuickAccess,
}), }),
this.quickAccessPanel(path, titleKey, currentQuickAccess), this.quickAccessPanel(path, titleKey),
]; ];
return result; return result;
@ -294,14 +269,13 @@ export default createWidget("user-menu", {
} }
}, },
quickAccessPanel(path, titleKey, currentQuickAccess) { quickAccessPanel(path, titleKey) {
const { showLogoutButton } = this.settings; const { showLogoutButton } = this.settings;
// This deliberately does NOT fallback to a default quick access panel. // This deliberately does NOT fallback to a default quick access panel.
return this.attach(`quick-access-${this.state.currentQuickAccess}`, { return this.attach(`quick-access-${this.state.currentQuickAccess}`, {
path, path,
showLogoutButton, showLogoutButton,
titleKey, titleKey,
currentQuickAccess,
}); });
}, },
}); });

View File

@ -416,10 +416,6 @@ div.menu-links-header {
flex: 1 1 auto; flex: 1 1 auto;
padding: 0.65em 0.25em 0.75em; padding: 0.65em 0.25em 0.75em;
justify-content: center; justify-content: center;
svg {
pointer-events: none;
}
} }
} }