-
Notifications
You must be signed in to change notification settings - Fork 274
fix(ui5-button): announce accessible name #11396
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -37,6 +37,8 @@ import { | |||||||||||||||||
BUTTON_ARIA_TYPE_REJECT, | ||||||||||||||||||
BUTTON_ARIA_TYPE_EMPHASIZED, | ||||||||||||||||||
BUTTON_ARIA_TYPE_ATTENTION, | ||||||||||||||||||
BUTTON_BADGE_ONE_ITEM, | ||||||||||||||||||
BUTTON_BADGE_MANY_ITEMS, | ||||||||||||||||||
} from "./generated/i18n/i18n-defaults.js"; | ||||||||||||||||||
|
||||||||||||||||||
// Styles | ||||||||||||||||||
|
@@ -522,15 +524,32 @@ class Button extends UI5Element implements IButton { | |||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
get ariaLabelText() { | ||||||||||||||||||
return getEffectiveAriaLabelText(this); | ||||||||||||||||||
const ariaLabelText = getEffectiveAriaLabelText(this) || ""; | ||||||||||||||||||
const typeLabelText = this.hasButtonType ? this.buttonTypeText : ""; | ||||||||||||||||||
const internalLabelText = `${typeLabelText} ${this.effectiveBadgeDescriptionText}`.trim(); | ||||||||||||||||||
|
||||||||||||||||||
return `${ariaLabelText} ${internalLabelText}`.trim(); | ||||||||||||||||||
Comment on lines
+529
to
+531
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Consider handling cases where both the effective aria label and button type text are empty to avoid potential extra spaces, even though trim() is used; a more modular construction of the final label might improve future maintenance.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
get ariaDescriptionText() { | ||||||||||||||||||
const ariaDescribedByText = this.hasButtonType ? this.buttonTypeText : ""; | ||||||||||||||||||
const accessibleDescription = this.accessibleDescription || ""; | ||||||||||||||||||
const ariaDescriptionText = `${ariaDescribedByText} ${accessibleDescription}`.trim(); | ||||||||||||||||||
return this.accessibleDescription === "" ? undefined : this.accessibleDescription; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
get effectiveBadgeDescriptionText() { | ||||||||||||||||||
if (!this.shouldRenderBadge) { | ||||||||||||||||||
return ""; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
const badgeEffectiveText = this.badge[0].effectiveText; | ||||||||||||||||||
|
||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Adding a comment to explain the rationale for using distinct i18n keys (BUTTON_BADGE_ONE_ITEM vs. BUTTON_BADGE_MANY_ITEMS) for singular and plural badge values would help improve code clarity.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||
return ariaDescriptionText || undefined; | ||||||||||||||||||
switch (badgeEffectiveText) { | ||||||||||||||||||
case "": | ||||||||||||||||||
return badgeEffectiveText; | ||||||||||||||||||
case "1": | ||||||||||||||||||
return Button.i18nBundle.getText(BUTTON_BADGE_ONE_ITEM, badgeEffectiveText); | ||||||||||||||||||
default: | ||||||||||||||||||
return Button.i18nBundle.getText(BUTTON_BADGE_MANY_ITEMS, badgeEffectiveText); | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
get _isSubmit() { | ||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Ensure that the test description accurately reflects the new behavior, verifying that the aria-description is set as expected for different design scenarios.
Copilot uses AI. Check for mistakes.