Skip to content

Commit c03e359

Browse files
authored
fix(ObjectStatus): screen readers announce "button" only once (#7047)
Fixes #7039
1 parent 6ababe1 commit c03e359

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

packages/main/src/components/ObjectStatus/ObjectStatus.cy.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ describe('ObjectStatus', () => {
238238
cy.findByText('Object Status').should('exist').and('have.css', 'font-size', '0px');
239239

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

255255
it('emptyIndicator', () => {

packages/main/src/components/ObjectStatus/index.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ const ObjectStatus = forwardRef<HTMLDivElement | HTMLButtonElement, ObjectStatus
170170
emptyIndicator,
171171
stateAnnouncementText,
172172
large,
173+
'aria-roledescription': ariaRoleDescription,
173174
...rest
174175
} = props;
175176
const i18nBundle = useI18nBundle('@ui5/webcomponents-react');
@@ -214,6 +215,7 @@ const ObjectStatus = forwardRef<HTMLDivElement | HTMLButtonElement, ObjectStatus
214215
);
215216

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

218220
return (
219221
<TagName
@@ -225,12 +227,18 @@ const ObjectStatus = forwardRef<HTMLDivElement | HTMLButtonElement, ObjectStatus
225227
onClick={interactive ? onClick : undefined}
226228
tabIndex={interactive ? 0 : undefined}
227229
data-icon-only={!children}
228-
role={interactive ? 'button' : 'group'}
230+
role={interactive ? undefined : 'group'}
231+
aria-roledescription={roleDesc || undefined}
229232
{...rest}
230233
>
231-
<span className={classNames.pseudoInvisibleText} data-component-name="ObjectStatusInvisibleDescriptionContainer">
232-
{interactive ? i18nBundle.getText(ARIA_OBJ_STATUS_DESC) : i18nBundle.getText(ARIA_OBJ_STATUS_DESC_INACTIVE)}
233-
</span>
234+
{!interactive && (
235+
<span
236+
className={classNames.pseudoInvisibleText}
237+
data-component-name="ObjectStatusInvisibleDescriptionContainer"
238+
>
239+
{i18nBundle.getText(ARIA_OBJ_STATUS_DESC_INACTIVE)}
240+
</span>
241+
)}
234242
{iconToRender && (
235243
<span className={classNames.icon} data-icon-only={!children} data-component-name="ObjectStatusIconContainer">
236244
{iconToRender}

0 commit comments

Comments
 (0)