aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/design-system/src
diff options
context:
space:
mode:
authorMathieu Suen <mathieu.suen@sonarsource.com>2024-03-18 12:20:14 +0100
committersonartech <sonartech@sonarsource.com>2024-03-18 20:02:30 +0000
commita43209f6b80a8c7138f7ed1b74e4138f5238b5cd (patch)
tree07f9c6e72ef901c2eb8621e51bfa998a26697cd7 /server/sonar-web/design-system/src
parent03600808205c4f6df77713dbd40ee0a6e9c25a48 (diff)
downloadsonarqube-a43209f6b80a8c7138f7ed1b74e4138f5238b5cd.tar.gz
sonarqube-a43209f6b80a8c7138f7ed1b74e4138f5238b5cd.zip
SONAR-21808 Add the failed badge on software quality cards
Diffstat (limited to 'server/sonar-web/design-system/src')
-rw-r--r--server/sonar-web/design-system/src/components/Badge.tsx7
-rw-r--r--server/sonar-web/design-system/src/components/__tests__/Badge-test.tsx10
2 files changed, 10 insertions, 7 deletions
diff --git a/server/sonar-web/design-system/src/components/Badge.tsx b/server/sonar-web/design-system/src/components/Badge.tsx
index 54ed4d62289..1746a417d0c 100644
--- a/server/sonar-web/design-system/src/components/Badge.tsx
+++ b/server/sonar-web/design-system/src/components/Badge.tsx
@@ -32,8 +32,7 @@ const variantList: Record<BadgeVariant, ThemeColors> = {
counterFailed: 'badgeCounterFailed',
};
-interface BadgeProps {
- children: string | number;
+interface BadgeProps extends React.PropsWithChildren {
className?: string;
title?: string;
variant?: BadgeVariant;
@@ -41,9 +40,9 @@ interface BadgeProps {
export function Badge({ className, children, title, variant = 'default' }: BadgeProps) {
const commonProps = {
- 'aria-label': title ?? children.toString(),
+ 'aria-label': title,
className,
- role: 'status',
+ role: title ? 'img' : 'presentation',
title,
};
diff --git a/server/sonar-web/design-system/src/components/__tests__/Badge-test.tsx b/server/sonar-web/design-system/src/components/__tests__/Badge-test.tsx
index 97f901852d8..5429ccc2a16 100644
--- a/server/sonar-web/design-system/src/components/__tests__/Badge-test.tsx
+++ b/server/sonar-web/design-system/src/components/__tests__/Badge-test.tsx
@@ -23,10 +23,14 @@ import { Badge } from '../Badge';
it('renders badge correctly', () => {
render(<Badge>foo</Badge>);
- expect(screen.getByRole('status')).toBeInTheDocument();
+ expect(screen.getByText('foo')).toBeInTheDocument();
});
it('renders counter correctly', () => {
- render(<Badge variant="counter">23</Badge>);
- expect(screen.getByRole('status')).toHaveAttribute('aria-label', '23');
+ render(
+ <Badge title="This 23" variant="counter">
+ 23
+ </Badge>,
+ );
+ expect(screen.getByRole('img')).toHaveAccessibleName('This 23');
});