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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve profile picture settings accessibility #10470

Merged
merged 2 commits into from
Mar 29, 2023
Merged
Changes from 1 commit
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
15 changes: 9 additions & 6 deletions src/components/views/settings/AvatarSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ const AvatarSetting: React.FC<IProps> = ({ avatarUrl, avatarAltText, avatarName,
element="div"
onClick={uploadAvatar ?? null}
className="mx_AvatarSetting_avatarPlaceholder"
aria-labelledby={a11yId.current}
aria-labelledby={uploadAvatar ? a11yId.current : undefined}
// Inhibit tab stop as we have explicit upload/remove buttons
tabIndex={-1}
{...hoveringProps}
/>
);
Expand All @@ -53,14 +55,15 @@ const AvatarSetting: React.FC<IProps> = ({ avatarUrl, avatarAltText, avatarName,
element="img"
src={avatarUrl}
alt={avatarAltText}
aria-label={avatarAltText}
onClick={uploadAvatar ?? null}
// Inhibit tab stop as we have explicit upload/remove buttons
tabIndex={-1}
{...hoveringProps}
/>
);
}

let uploadAvatarBtn;
let uploadAvatarBtn: JSX.Element | undefined;
if (uploadAvatar) {
// insert an empty div to be the host for a css mask containing the upload.svg
uploadAvatarBtn = (
Expand All @@ -73,7 +76,7 @@ const AvatarSetting: React.FC<IProps> = ({ avatarUrl, avatarAltText, avatarName,
);
}

let removeAvatarBtn;
let removeAvatarBtn: JSX.Element | undefined;
if (avatarUrl && removeAvatar) {
removeAvatarBtn = (
<AccessibleButton onClick={removeAvatar} kind="link_sm">
Expand All @@ -87,11 +90,11 @@ const AvatarSetting: React.FC<IProps> = ({ avatarUrl, avatarAltText, avatarName,
mx_AvatarSetting_avatar_hovering: isHovering && uploadAvatar,
});
return (
<div className={avatarClasses}>
<div className={avatarClasses} role="group" aria-label={avatarAltText}>
{avatarElement}
<div className="mx_AvatarSetting_hover" aria-hidden="true">
<div className="mx_AvatarSetting_hoverBg" />
<span id={a11yId.current}>{_t("Upload")}</span>
{uploadAvatar && <span id={a11yId.current}>{_t("Upload")}</span>}
</div>
{uploadAvatarBtn}
{removeAvatarBtn}
Expand Down