Skip to content

feat(ui5-avatar-badge): add accessibleName property for custom tooltip#13390

Merged
plamenivanov91 merged 9 commits intomainfrom
avatar-tooltip
Apr 22, 2026
Merged

feat(ui5-avatar-badge): add accessibleName property for custom tooltip#13390
plamenivanov91 merged 9 commits intomainfrom
avatar-tooltip

Conversation

@plamenivanov91
Copy link
Copy Markdown
Contributor

@plamenivanov91 plamenivanov91 commented Apr 15, 2026

The badge now supports a new accessibleName property to customize the
tooltip text displayed on hover. When not provided, the badge uses a
fallback strategy:

User-provided accessibleName (highest priority)
Icon accessibility metadata when available
Derived icon name (lowest priority)

This gives developers full control over badge accessibility while
preserving sensible defaults for icons with and without semantic labels.

Added public accessibleName property
Resolved icon accessible names from registered icon accessibility metadata
Updated Icon mode from "Decorative" to "Image" to enable tooltip display
Added Cypress coverage for custom, derived, and invalid icon cases
Updated documentation for accessibleName behavior
Fixed React sample alignment by wrapping avatars in a flex container
Updated HTML and React test pages with accessibility examples

…p text

The badge now supports a new accessibleName property to customize the tooltip
text displayed on hover. When not provided, the badge uses a smart fallback:
1. User-provided accessibleName (highest priority)
2. Icon semantic name (e.g., "edit" -> "Edit")
3. i18n "Avatar" text from message bundle (lowest, ensures always defined)

This gives developers full control over badge accessibility while maintaining
sensible defaults for better user experience and accessibility.

- Added public accessibleName property
- Integrated i18n bundle support with @i18n decorator for fallback
- Updated Icon mode from "Decorative" to "Image" to enable tooltip display
- Added comprehensive Cypress tests for default, custom, and invalid icon cases
- Updated documentation with accessibleName property explanation
- Fixed React sample alignment by wrapping avatars in flex container
- Updated HTML and React test pages with accessibility examples
@plamenivanov91 plamenivanov91 requested a review from kgogov April 15, 2026 12:40
@ui5-webcomponents-bot
Copy link
Copy Markdown
Collaborator

ui5-webcomponents-bot commented Apr 15, 2026

🧹 Preview deployment cleaned up: https://pr-13390--ui5-webcomponents.netlify.app

@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview April 15, 2026 12:47 Inactive
@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview April 15, 2026 13:42 Inactive
@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview April 15, 2026 14:20 Inactive
@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview April 16, 2026 06:46 Inactive
@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview April 20, 2026 14:15 Inactive
@kgogov
Copy link
Copy Markdown
Contributor

kgogov commented Apr 21, 2026

Code review

Found 2 issues:

  1. The AVATAR_TOOLTIP i18n fallback (AvatarBadge.i18nBundle.getText(AVATAR_TOOLTIP)) in the else branch is unreachable dead code. icon is guaranteed to be a non-empty string at line 132 — the if (!icon) { return; } guard at line 115 exits the function for any falsy value, so the ternary's false branch never executes. The comment on line 131 ("If not possible, fall back to i18n 'Avatar' text") describes code that can never run.

// Derive from icon name (e.g., "edit" -> "Edit")
// If not possible, fall back to i18n "Avatar" text
this.effectiveAccessibleName = icon
? icon.charAt(0).toUpperCase() + icon.slice(1)
: AvatarBadge.i18nBundle.getText(AVATAR_TOOLTIP);
}

  1. The fallback in the else branch skips checking iconData.accData entirely. For icons that have a registered i18n label — e.g. message-error has accData with defaultText: "Error" — the code produces "Message-error" instead of "Error". Icon.ts already handles this correctly at lines 335–340 by reading from accData first. Icons without accData (edit, sys-enter-2, etc.) are unaffected since no better label is available for those.
Icon accData Correct label Current code produces
edit null (none) "Edit"
sys-enter-2 null (none) "Sys-enter-2"
message-error ICON_MESSAGE_ERROR "Error" "Message-error"
person-placeholder null (none) "Person-placeholder"

// Derive from icon name (e.g., "edit" -> "Edit")
// If not possible, fall back to i18n "Avatar" text
this.effectiveAccessibleName = icon
? icon.charAt(0).toUpperCase() + icon.slice(1)
: AvatarBadge.i18nBundle.getText(AVATAR_TOOLTIP);
}

@kgogov
Copy link
Copy Markdown
Contributor

kgogov commented Apr 21, 2026

Screenshot 2026-04-21 at 15 05 04

Copy link
Copy Markdown
Contributor

@kgogov kgogov left a comment

Choose a reason for hiding this comment

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

A couple of things to address before this is ready to merge — see the comments above.

Use icon accessibility metadata before deriving a label from the icon name.

Remove the unreachable Avatar tooltip fallback branch and the unused
static i18n bundle wiring.
@plamenivanov91 plamenivanov91 requested a review from kgogov April 21, 2026 12:30
@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview April 21, 2026 12:35 Inactive
@kgogov
Copy link
Copy Markdown
Contributor

kgogov commented Apr 21, 2026

One more thing — the fix commit introduced a subtle gap.

onBeforeRendering now calls getI18nBundle(iconData.packageName) to resolve the icon's translated label, but @customElement is missing languageAware: true. This means when setLanguage() is called at runtime, the framework's re-render sweep skips AvatarBadge entirely — the tooltip label freezes in the initial language while everything else updates around it.

Icon.ts faces the same problem and solves it at line 104:

@customElement({
    tag: "ui5-icon",
    languageAware: true,  // Re-render on language change
    ...
})

One line, same decorator, same fix.

@customElement({
tag: "ui5-avatar-badge",
renderer: jsxRenderer,
styles: AvatarBadgeCss,
template: AvatarBadgeTemplate,
})
class AvatarBadge extends UI5Element {

@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview April 21, 2026 16:38 Inactive
Copy link
Copy Markdown
Contributor

@kgogov kgogov left a comment

Choose a reason for hiding this comment

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

All raised concerns have been addressed — the unreachable fallback branch, the missing accData check, and languageAware: true. The PR looks good.

@plamenivanov91 plamenivanov91 merged commit 4f1f6f0 into main Apr 22, 2026
28 of 31 checks passed
@plamenivanov91 plamenivanov91 deleted the avatar-tooltip branch April 22, 2026 07:37
@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview April 22, 2026 07:37 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants