Skip to content

Commit 96725e5

Browse files
fix(ui5-avatar-badge): correct accessible name fallback handling
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.
1 parent 6ddc169 commit 96725e5

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

packages/main/src/AvatarBadge.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
22
import customElement from "@ui5/webcomponents-base/dist/decorators/customElement.js";
33
import property from "@ui5/webcomponents-base/dist/decorators/property.js";
4-
import i18n from "@ui5/webcomponents-base/dist/decorators/i18n.js";
54
import jsxRenderer from "@ui5/webcomponents-base/dist/renderer/JsxRenderer.js";
6-
import type I18nBundle from "@ui5/webcomponents-base/dist/i18nBundle.js";
75
import { getIconData, getIconDataSync } from "@ui5/webcomponents-base/dist/asset-registries/Icons.js";
6+
import { getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
87

98
// Template
109
import AvatarBadgeTemplate from "./AvatarBadgeTemplate.js";
1110

1211
// Styles
1312
import AvatarBadgeCss from "./generated/themes/AvatarBadge.css.js";
1413

15-
import { AVATAR_TOOLTIP } from "./generated/i18n/i18n-defaults.js";
16-
1714
import ValueState from "@ui5/webcomponents-base/dist/types/ValueState.js";
1815

1916
const ICON_NOT_FOUND = "ICON_NOT_FOUND";
@@ -107,9 +104,6 @@ class AvatarBadge extends UI5Element {
107104
@property({ noAttribute: true })
108105
effectiveAccessibleName?: string;
109106

110-
@i18n("@ui5/webcomponents")
111-
static i18nBundle: I18nBundle;
112-
113107
async onBeforeRendering() {
114108
const icon = this.icon;
115109
if (!icon) {
@@ -126,12 +120,17 @@ class AvatarBadge extends UI5Element {
126120
} else if (this.accessibleName) {
127121
// User-provided accessible name takes precedence
128122
this.effectiveAccessibleName = this.accessibleName;
123+
} else if (iconData && iconData !== ICON_NOT_FOUND && iconData.accData) {
124+
// Use the icon's registered i18n label (e.g., message-error -> "Error")
125+
if (iconData.packageName) {
126+
const i18nBundle = await getI18nBundle(iconData.packageName);
127+
this.effectiveAccessibleName = i18nBundle.getText(iconData.accData) || undefined;
128+
} else {
129+
this.effectiveAccessibleName = iconData.accData.defaultText || undefined;
130+
}
129131
} else {
130132
// Derive from icon name (e.g., "edit" -> "Edit")
131-
// If not possible, fall back to i18n "Avatar" text
132-
this.effectiveAccessibleName = icon
133-
? icon.charAt(0).toUpperCase() + icon.slice(1)
134-
: AvatarBadge.i18nBundle.getText(AVATAR_TOOLTIP);
133+
this.effectiveAccessibleName = icon.charAt(0).toUpperCase() + icon.slice(1);
135134
}
136135
}
137136
}

0 commit comments

Comments
 (0)