diff --git a/framework/core/js/src/common/helpers/avatar.tsx b/framework/core/js/src/common/helpers/avatar.tsx index aab82696d2..15ad09eff7 100644 --- a/framework/core/js/src/common/helpers/avatar.tsx +++ b/framework/core/js/src/common/helpers/avatar.tsx @@ -31,13 +31,27 @@ export default function avatar(user: User | null, attrs: ComponentAttrs = {}): M if (hasTitle) attrs.title = attrs.title || username; + // Alt text logic: + // If the `alt` attribute is set to null or false, we don't want to give the + // avatar an alt description. If it hasn't been provided, we'll default it to + // the user's display name *when rendering an * so screen readers have context. + const hasAlt: boolean | string = attrs.alt === 'undefined' || attrs.alt; + if (!hasAlt) delete attrs.alt; + if (avatarUrl) { - return ; + // Default alt to username unless explicitly overridden. + if (attrs.alt === undefined) { + attrs.alt = username; + } + + return ; } content = username.charAt(0).toUpperCase(); attrs.style = { '--avatar-bg': user.color() }; } + // Note: We intentionally do NOT set `alt` when rendering the fallback , + // as `alt` is only valid for certain elements (e.g., , , ). return {content}; }