A platform for community discussion. Free, open, simple.
A11Y: Improve user card accessibility (#18348)
Keegan Georgeca1038187f35
diff --git a/app/assets/javascripts/discourse/app/mixins/card-contents-base.js b/app/assets/javascripts/discourse/app/mixins/card-contents-base.jsindex 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.hbsindex 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 @@<div class="names"><h1 class="{{this.staff}} {{this.newUser}} {{if this.nameFirst "full-name" "username"}}">{{#if this.user.profile_hidden}}- <span class="name-username-wrapper">+ <span id="discourse-user-card-title" class="name-username-wrapper">{{if this.nameFirst this.user.name (format-username this.user.username)}}</span>{{else}}<a href={{this.user.path}} {{action "showUser" this.user}} class="user-profile-link">- <span class="name-username-wrapper">+ <span id="discourse-user-card-title" class="name-username-wrapper">{{if this.nameFirst this.user.name (format-username this.user.username)}}</span>{{user-status this.user currentUser=this.currentUser}}diff --git a/app/assets/javascripts/discourse/app/templates/user-card.hbs b/app/assets/javascripts/discourse/app/templates/user-card.hbsindex ba2df96cac1..9407edab97d 100644--- a/app/assets/javascripts/discourse/app/templates/user-card.hbs+++ b/app/assets/javascripts/discourse/app/templates/user-card.hbs@@ -2,6 +2,5 @@<div class="card-cloak hidden"></div>{{/if}}-<UserCardContents @topic={{this.topic.model}} @showUser={{action "showUser"}} @filterPosts={{action "filterPosts"}} @composePrivateMessage={{route-action "composePrivateMessage"}} @createNewMessageViaParams={{route-action "createNewMessageViaParams"}} />-+<UserCardContents @topic={{this.topic.model}} @showUser={{action "showUser"}} @filterPosts={{action "filterPosts"}} @composePrivateMessage={{route-action "composePrivateMessage"}} @createNewMessageViaParams={{route-action "createNewMessageViaParams"}} role="dialog" aria-labelledby="discourse-user-card-title"/><GroupCardContents @topic={{this.topic.model}} @showUser={{action "showUser"}} @showGroup={{action "showGroup"}} @createNewMessageViaParams={{route-action "createNewMessageViaParams"}} />diff --git a/app/assets/stylesheets/common/components/user-card.scss b/app/assets/stylesheets/common/components/user-card.scssindex 14d723e9cfa..a209bc5596b 100644--- a/app/assets/stylesheets/common/components/user-card.scss+++ b/app/assets/stylesheets/common/components/user-card.scss@@ -53,7 +53,7 @@ $avatar_margin: -50px; // negative margin makes avatars extend above cardsclear: both;}a.card-huge-avatar {- outline: none;+ display: block;}.bio {@include line-clamp(2);@@ -70,6 +70,11 @@ $avatar_margin: -50px; // negative margin makes avatars extend above cards.user-profile-link {display: flex;align-items: center;++ &:focus {+ border: 1px solid;+ @include default-focus;+ }}.d-icon {