Skip to content
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

Badge: Ensure label follows correct tone #1544

Merged
merged 2 commits into from
Jul 29, 2024
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
13 changes: 13 additions & 0 deletions .changeset/perfect-rockets-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'braid-design-system': patch
---

---
updated:
- Badge
---

**Badge:** Ensure label follows correct tone

Ensure that the foreground text of a `Badge` always follows the correct tone for the background colour.
Fixes a bug where using a `Badge` in a `List` that overrides the default tone would result in the `Badge` text following the `List` tone instead of the `Badge` tone.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import type { ComponentScreenshot } from 'site/types';
import { Badge, Inline, Heading } from '../';
import { Badge, Inline, Heading, List } from '../';

export const screenshots: ComponentScreenshot = {
screenshotWidths: [320],
Expand Down Expand Up @@ -108,5 +108,16 @@ export const screenshots: ComponentScreenshot = {
</Badge>
),
},
{
label: 'Test: Badge text should follow tone not default set by `List`',
Example: () => (
<List tone="secondary">
<Badge tone="critical">Critical</Badge>
<Badge tone="critical" weight="strong">
Critical
</Badge>
</List>
),
},
],
};
55 changes: 30 additions & 25 deletions packages/braid-design-system/src/lib/components/Badge/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import buildDataAttributes, {
type DataAttributeMap,
} from '../private/buildDataAttributes';
import { Bleed } from '../Bleed/Bleed';
import { DefaultTextPropsProvider } from '../private/defaultTextProps';

type ValueOrArray<T> = T | T[];

Expand Down Expand Up @@ -83,35 +84,39 @@ export const Badge = forwardRef<HTMLSpanElement, BadgeProps>(
);

const content = (
<Box
component="span"
display="flex"
cursor="default"
{...buildDataAttributes({ data, validateRestProps: restProps })}
>
// Ensures the foreground text tone follows the default
// for the selected background colour
<DefaultTextPropsProvider tone="neutral">
<Box
component="span"
id={id}
ref={ref}
tabIndex={tabIndex}
aria-describedby={ariaDescribedBy}
title={
title ??
(!ariaDescribedBy ? stringifyChildren(children) : undefined)
}
background={
weight === 'strong' ? tone : lightModeBackgroundForTone[tone]
}
paddingY={verticalPadding}
paddingX="xsmall"
borderRadius="standard"
overflow="hidden"
display="flex"
cursor="default"
{...buildDataAttributes({ data, validateRestProps: restProps })}
>
<Text size="xsmall" weight="medium" maxLines={1}>
{children}
</Text>
<Box
component="span"
id={id}
ref={ref}
tabIndex={tabIndex}
aria-describedby={ariaDescribedBy}
title={
title ??
(!ariaDescribedBy ? stringifyChildren(children) : undefined)
}
background={
weight === 'strong' ? tone : lightModeBackgroundForTone[tone]
}
paddingY={verticalPadding}
paddingX="xsmall"
borderRadius="standard"
overflow="hidden"
>
<Text size="xsmall" weight="medium" maxLines={1}>
{children}
</Text>
</Box>
</Box>
</Box>
</DefaultTextPropsProvider>
);

return bleedY ? (
Expand Down