Skip to content

Conversation

@imorland
Copy link
Member

@imorland imorland commented Oct 2, 2025

This PR improves accessibility of the avatar helper by ensuring that avatars include meaningful alt text by default.
• If a user is present and no alt attribute is provided, it falls back to the user’s display name.
• If explicitly set to null/false, the alt attribute is omitted (treated as decorative).
• For cases where no user is passed, the alt defaults to an empty string.

This change aligns avatars with WCAG guidelines by providing screen readers with descriptive text, while still allowing developers to override or suppress alt when needed.

A follow-up PR for 2.x will also be made

Fixes #0000

Changes proposed in this pull request:

Reviewers should focus on:

Screenshot

Necessity

  • Has the problem that is being solved here been clearly explained?
  • If applicable, have various options for solving this problem been considered?
  • For core PRs, does this need to be in core, or could it be in an extension?
  • Are we willing to maintain this for years / potentially forever?

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).
  • Core developer confirmed locally this works as intended.
  • Tests have been added, or are not appropriate here.

Required changes:

  • Related documentation PR: (Remove if irrelevant)

@imorland imorland requested a review from a team as a code owner October 2, 2025 07:43
@imorland imorland added this to the 1.8.11 milestone Oct 2, 2025
@imorland imorland added the type/accessibility Issues relating to accessibility (keyboard navigation, screenreaders, text contrast, etc.) label Oct 2, 2025
Copy link
Contributor

@DavideIadeluca DavideIadeluca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally — working as expected, though I have some improvements for the case where no avatarUrl exists

The alt property should be omitted in case of no user avatar (alt on span is invalid)

Copy link
Contributor

@DavideIadeluca DavideIadeluca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested locally, looks good to me now

@imorland imorland merged commit bad9925 into 1.x Oct 3, 2025
360 checks passed
@imorland imorland deleted the im/avatar-a11y branch October 3, 2025 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/accessibility Issues relating to accessibility (keyboard navigation, screenreaders, text contrast, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants