Skip to content

Commit 6d867a0

Browse files
authored
fix(ui): displaying badges in alerts (#97167)
couple of issues here: 1. In UI1, displaying a `Badge` (Action required) inside `trailingItems` of an `Alert` didn’t work (but looks fine in UI2): <img width="919" height="347" alt="Screenshot 2025-08-05 at 15 04 15" src="https://github.com/user-attachments/assets/ec93e97b-bda1-46c1-ae18-4141ebebf5b9" /> 2. Buttons with size `xs` inside an `Alert` made the text misaligned with the leading icon in UI2, so I changed it to size `zero` in the stories. 3. The `Action Required` Badge inside the Alert wasn’t vertically centered. 2 and 3 can be observed here: <img width="919" height="347" alt="Screenshot 2025-08-05 at 15 04 56" src="https://github.com/user-attachments/assets/e7076c7c-466b-4803-a806-4412f9c37afb" /> --- Fixed versions: <img width="919" height="347" alt="Screenshot 2025-08-05 at 14 50 33" src="https://github.com/user-attachments/assets/d8c58148-7c1b-4f26-9ccf-fcbde27c05d0" /> <img width="919" height="347" alt="Screenshot 2025-08-05 at 14 50 27" src="https://github.com/user-attachments/assets/50462701-9091-4acb-91ef-f09511d4a26b" />
1 parent 8a1df4f commit 6d867a0

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

static/app/components/core/alert/index.mdx

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ resources:
1414

1515
import {Alert} from 'sentry/components/core/alert';
1616
import {AlertLink} from 'sentry/components/core/alert/alertLink';
17+
import {Badge} from 'sentry/components/core/badge';
1718
import {Button} from 'sentry/components/core/button';
19+
import {Flex} from 'sentry/components/core/layout';
1820
import {IconAdd, IconDelete, IconEdit, IconMail} from 'sentry/icons';
1921
import * as Storybook from 'sentry/stories';
2022

@@ -167,31 +169,24 @@ You can control the initial expansion state of alerts with the `defaultExpanded`
167169

168170
### Trailing Items
169171

170-
Add interactive elements like buttons or links to the right side of alerts using the `trailingItems` prop.
172+
Add interactive elements like buttons, links or badges to the right side of alerts using the `trailingItems` prop.
171173

172174
<Storybook.Demo>
173175
<Alert.Container>
174-
<Alert
175-
type="info"
176-
trailingItems={
177-
<Button size="xs" priority="primary">
178-
Take Action
179-
</Button>
180-
}
181-
>
182-
This alert has a trailing action button
176+
<Alert type="info" trailingItems={<Badge type="warning">Action Required</Badge>}>
177+
This alert has a trailing bagde
183178
</Alert>
184179
<Alert
185180
type="error"
186181
trailingItems={
187-
<div>
188-
<Button size="xs" priority="danger" icon={<IconDelete />}>
182+
<Flex gap="sm">
183+
<Button size="zero" priority="danger" icon={<IconDelete />}>
189184
Delete
190185
</Button>
191-
<Button size="xs" priority="muted" icon={<IconEdit />}>
186+
<Button size="zero" priority="muted" icon={<IconEdit />}>
192187
Edit
193188
</Button>
194-
</div>
189+
</Flex>
195190
}
196191
>
197192
This alert has multiple trailing actions
@@ -203,24 +198,24 @@ Add interactive elements like buttons or links to the right side of alerts using
203198
<Alert
204199
type="info"
205200
trailingItems={
206-
<Button size="xs" priority="primary">
201+
<Button size="zero" priority="primary">
207202
Take Action
208203
</Button>
209204
}
210205
>
211-
This alert has a trailing action button
206+
This alert has a trailing badge
212207
</Alert>
213208
<Alert
214209
type="error"
215210
trailingItems={
216-
<div>
217-
<Button size="xs" priority="danger" icon={<IconDelete />}>
211+
<Flex gap="sm">
212+
<Button size="zero" priority="danger" icon={<IconDelete />}>
218213
Delete
219214
</Button>
220-
<Button size="xs" priority="muted" icon={<IconEdit />}>
215+
<Button size="zero" priority="muted" icon={<IconEdit />}>
221216
Edit
222217
</Button>
223-
</div>
218+
</Flex>
224219
}
225220
>
226221
This alert has multiple trailing actions

static/app/components/core/alert/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,12 @@ function getAlertColors(theme: Theme, type: NonNullable<AlertProps['type']>) {
169169

170170
function getAlertGridLayout(p: AlertProps) {
171171
if (p.showIcon) {
172-
return `min-content 1fr ${p.trailingItems ? 'min-content' : ''} ${
172+
return `min-content 1fr ${p.trailingItems ? 'auto' : ''} ${
173173
p.expand ? 'min-content' : ''
174174
}`;
175175
}
176176

177-
return `1fr ${p.trailingItems ? 'min-content' : ''} ${p.expand ? 'min-content' : ''}`;
177+
return `1fr ${p.trailingItems ? 'auto' : ''} ${p.expand ? 'min-content' : ''}`;
178178
}
179179

180180
const AlertPanel = styled('div')<AlertProps & {hovered: boolean}>`

0 commit comments

Comments
 (0)