mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 23:07:28 +08:00
A11Y: Improve small-post markup for screen readers (#23732)
This commit is contained in:
@ -94,7 +94,17 @@ export function resetPostSmallActionClassesCallbacks() {
|
|||||||
|
|
||||||
export default createWidget("post-small-action", {
|
export default createWidget("post-small-action", {
|
||||||
buildKey: (attrs) => `post-small-act-${attrs.id}`,
|
buildKey: (attrs) => `post-small-act-${attrs.id}`,
|
||||||
tagName: "div.small-action.onscreen-post",
|
tagName: "article.small-action.onscreen-post",
|
||||||
|
|
||||||
|
buildAttributes(attrs) {
|
||||||
|
return {
|
||||||
|
"aria-label": I18n.t("share.post", {
|
||||||
|
postNumber: attrs.post_number,
|
||||||
|
username: attrs.username,
|
||||||
|
}),
|
||||||
|
role: "region",
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
buildId(attrs) {
|
buildId(attrs) {
|
||||||
return `post_${attrs.post_number}`;
|
return `post_${attrs.post_number}`;
|
||||||
@ -130,6 +140,7 @@ export default createWidget("post-small-action", {
|
|||||||
template: attrs.avatar_template,
|
template: attrs.avatar_template,
|
||||||
username: attrs.username,
|
username: attrs.username,
|
||||||
url: attrs.usernameUrl,
|
url: attrs.usernameUrl,
|
||||||
|
ariaHidden: false,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ export function avatarImg(wanted, attrs) {
|
|||||||
height: size,
|
height: size,
|
||||||
src: getURLWithCDN(url),
|
src: getURLWithCDN(url),
|
||||||
title,
|
title,
|
||||||
"aria-label": title,
|
"aria-hidden": true,
|
||||||
loading: "lazy",
|
loading: "lazy",
|
||||||
tabindex: "-1",
|
tabindex: "-1",
|
||||||
},
|
},
|
||||||
@ -73,8 +73,19 @@ export function avatarFor(wanted, attrs, linkAttrs) {
|
|||||||
const attributes = {
|
const attributes = {
|
||||||
href: attrs.url,
|
href: attrs.url,
|
||||||
"data-user-card": attrs.username,
|
"data-user-card": attrs.username,
|
||||||
"aria-hidden": true,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// often avatars are paired with usernames,
|
||||||
|
// making them redundant for screen readers
|
||||||
|
// so we hide the avatar from screen readers by default
|
||||||
|
if (attrs.ariaHidden === false) {
|
||||||
|
attributes["aria-label"] = I18n.t("user.profile_possessive", {
|
||||||
|
username: attrs.username,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
attributes["aria-hidden"] = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (linkAttrs) {
|
if (linkAttrs) {
|
||||||
Object.assign(attributes, linkAttrs);
|
Object.assign(attributes, linkAttrs);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user