Skip to content

fix(ObjectStatus): screen readers announce "button" only once #7047

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

Merged
merged 3 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ describe('ObjectStatus', () => {
cy.findByText('Object Status').should('exist').and('have.css', 'font-size', '0px');

cy.mount(
<ObjectStatus onClick={click} interactive>
<ObjectStatus onClick={click} interactive data-testid="os">
Content
</ObjectStatus>
);
Expand All @@ -249,7 +249,7 @@ describe('ObjectStatus', () => {
cy.get('@clickSpy').should('have.been.calledTwice');
cy.findByText('Content').realPress('Space');
cy.get('@clickSpy').should('have.been.calledThrice');
cy.findByText('Object Status Button').should('exist').and('have.css', 'font-size', '0px');
cy.findByTestId('os').should('have.attr', 'aria-roledescription', 'Object Status Button');
});

it('emptyIndicator', () => {
Expand Down
16 changes: 12 additions & 4 deletions packages/main/src/components/ObjectStatus/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ const ObjectStatus = forwardRef<HTMLDivElement | HTMLButtonElement, ObjectStatus
emptyIndicator,
stateAnnouncementText,
large,
'aria-roledescription': ariaRoleDescription,
...rest
} = props;
const i18nBundle = useI18nBundle('@ui5/webcomponents-react');
Expand Down Expand Up @@ -214,6 +215,7 @@ const ObjectStatus = forwardRef<HTMLDivElement | HTMLButtonElement, ObjectStatus
);

const TagName = interactive ? 'button' : 'div';
const roleDesc = `${ariaRoleDescription ? `${ariaRoleDescription} ` : ''}${interactive ? i18nBundle.getText(ARIA_OBJ_STATUS_DESC) : ''}`;

return (
<TagName
Expand All @@ -225,12 +227,18 @@ const ObjectStatus = forwardRef<HTMLDivElement | HTMLButtonElement, ObjectStatus
onClick={interactive ? onClick : undefined}
tabIndex={interactive ? 0 : undefined}
data-icon-only={!children}
role={interactive ? 'button' : 'group'}
role={interactive ? undefined : 'group'}
aria-roledescription={roleDesc || undefined}
{...rest}
>
<span className={classNames.pseudoInvisibleText} data-component-name="ObjectStatusInvisibleDescriptionContainer">
{interactive ? i18nBundle.getText(ARIA_OBJ_STATUS_DESC) : i18nBundle.getText(ARIA_OBJ_STATUS_DESC_INACTIVE)}
</span>
{!interactive && (
<span
className={classNames.pseudoInvisibleText}
data-component-name="ObjectStatusInvisibleDescriptionContainer"
>
{i18nBundle.getText(ARIA_OBJ_STATUS_DESC_INACTIVE)}
</span>
)}
{iconToRender && (
<span className={classNames.icon} data-icon-only={!children} data-component-name="ObjectStatusIconContainer">
{iconToRender}
Expand Down
Loading