Skip to content

Commit de906a1

Browse files
authored
fix(MessageViewButton): make counter accessible to screen readers (#7602)
1 parent 60faf04 commit de906a1

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ describe('MessageViewButton', () => {
2323
});
2424
it('counter', () => {
2525
cy.mount(<MessageViewButton data-testid="btn" />);
26-
cy.findByTestId('btn').should('be.empty');
26+
cy.findByTestId('btn').should('be.empty').and('have.attr', 'accessible-name', 'Error Type');
2727
cy.mount(<MessageViewButton data-testid="btn" counter={0} />);
28-
cy.findByTestId('btn').should('be.empty');
28+
cy.findByTestId('btn').should('be.empty').and('have.attr', 'accessible-name', 'Error Type');
2929
cy.mount(<MessageViewButton data-testid="btn" counter={2} />);
30-
cy.findByTestId('btn').should('have.text', '2');
30+
cy.findByTestId('btn').should('have.text', '2').and('have.attr', 'accessible-name', '2 Error Type');
3131
});
3232
});

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export interface MessageViewButtonProptypes
2828
* Specifies the type of the button.
2929
*
3030
* __Note:__ `"None"` is displayed as `"Information"`.
31+
*
32+
* @default "Negative"
3133
*/
3234
type?: ValueState | keyof typeof ValueState;
3335
/**
@@ -76,7 +78,7 @@ const MessageViewButton = forwardRef<ButtonDomRef, MessageViewButtonProptypes>((
7678
{...rest}
7779
data-type={type}
7880
tooltip={tooltip ?? i18nBundle.getText(title)}
79-
accessibleName={accessibleName ?? label}
81+
accessibleName={accessibleName ?? `${counter > 0 ? `${counter} ` : ''}${label}`}
8082
>
8183
{counter > 0 && counter}
8284
</Button>

0 commit comments

Comments
 (0)