From ca1038187f35e76434e0b4d14f16aa6ae66e0d4b Mon Sep 17 00:00:00 2001 From: Keegan George Date: Tue, 27 Sep 2022 10:06:20 -0700 Subject: [PATCH] A11Y: Improve user card accessibility (#18348) --- .../discourse/app/mixins/card-contents-base.js | 9 +++++---- .../app/templates/components/user-card-contents.hbs | 4 ++-- .../javascripts/discourse/app/templates/user-card.hbs | 3 +-- app/assets/stylesheets/common/components/user-card.scss | 7 ++++++- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/discourse/app/mixins/card-contents-base.js b/app/assets/javascripts/discourse/app/mixins/card-contents-base.js index 602a983ca45..2489a28f7a3 100644 --- a/app/assets/javascripts/discourse/app/mixins/card-contents-base.js +++ b/app/assets/javascripts/discourse/app/mixins/card-contents-base.js @@ -1,5 +1,5 @@ import { alias, match } from "@ember/object/computed"; -import { next, schedule, throttle } from "@ember/runloop"; +import { schedule, throttle } from "@ember/runloop"; import DiscourseURL from "discourse/lib/url"; import Mixin from "@ember/object/mixin"; import afterTransition from "discourse/lib/after-transition"; @@ -7,6 +7,7 @@ import { escapeExpression } from "discourse/lib/utilities"; import { inject as service } from "@ember/service"; import { wantsNewWindow } from "discourse/lib/intercept-click"; import { bind } from "discourse-common/utils/decorators"; +import discourseLater from "discourse-common/lib/later"; const DEFAULT_SELECTOR = "#main-outlet"; @@ -279,10 +280,10 @@ export default Mixin.create({ // note: we DO NOT use afterRender here cause _positionCard may // run afterwards, if we allowed this to happen the usercard // may be offscreen and we may scroll all the way to it on focus - next(null, () => { + discourseLater(() => { const firstLink = this.element.querySelector("a"); firstLink && firstLink.focus(); - }); + }, 350); } }); }, @@ -364,8 +365,8 @@ export default Mixin.create({ @bind _escListener(event) { if (this.visible && event.key === "Escape") { - this._close(); this.cardTarget?.focus(); + this._close(); return; } }, diff --git a/app/assets/javascripts/discourse/app/templates/components/user-card-contents.hbs b/app/assets/javascripts/discourse/app/templates/components/user-card-contents.hbs index 294ba3e886a..f2614399f2d 100644 --- a/app/assets/javascripts/discourse/app/templates/components/user-card-contents.hbs +++ b/app/assets/javascripts/discourse/app/templates/components/user-card-contents.hbs @@ -36,12 +36,12 @@

{{#if this.user.profile_hidden}} - + {{if this.nameFirst this.user.name (format-username this.user.username)}} {{else}}