Skip to content

Commit 4c6000a

Browse files
author
Kubit
committed
Improve quickbutton roles props
1 parent 9bb190a commit 4c6000a

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/components/quickButton/__tests__/quickButton.test.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,26 @@ describe('QuickButton component', () => {
3434
expect(container).toHTMLValidate();
3535
expect(results).toHaveNoViolations();
3636
});
37+
it('Should have a correct html structure, when a role us provided', async () => {
38+
const { container } = renderProvider(
39+
<QuickButton {...mockProps} label={{ content: 'label' }} role="link" />
40+
);
41+
42+
const quickButton = screen.getByRole('link');
43+
const label = screen.getByText('label');
44+
45+
expect(quickButton).toBeDefined();
46+
expect(label).toBeDefined();
47+
48+
const results = await axe(container);
49+
// This is because the role is conditional
50+
expect(container).toHTMLValidate({
51+
rules: {
52+
'prefer-native-element': 'off',
53+
},
54+
});
55+
expect(results).toHaveNoViolations();
56+
});
3757

3858
it('Variant is optional', async () => {
3959
const { container } = renderProvider(<QuickButton {...mockProps} variant={undefined} />);

src/components/quickButton/quickButtonStandAlone.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const QuickButtonStandAloneComponent = (
1717
data-testid={props.dataTestId}
1818
disabled={props.state === QuickButtonState.DISABLED}
1919
id={props.buttonId}
20+
role={props.role}
2021
styles={props.styles}
2122
type={props.type}
2223
onClick={props.onClick}

src/components/quickButton/types/quickButton.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface IQuickButtonStandAlone {
2626
dataTestId?: string;
2727
type?: ButtonType;
2828
['aria-label']?: string;
29+
role?: string;
2930
}
3031

3132
/**

0 commit comments

Comments
 (0)