Skip to content

Commit db6c360

Browse files
brphelpsjoshblack
andauthoredJan 23, 2025
Banner allows critical variant to use ondismiss (#5583)
* Allow critical on dismiss, ready to test * add changeset * Update .changeset/blue-actors-rule.md Co-authored-by: Josh Black <joshblack@github.com> * Remove onDismiss action from Banner story * refactor(test): update to address eslint warnings --------- Co-authored-by: Josh Black <joshblack@github.com>
1 parent ccc3c99 commit db6c360

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed
 

‎.changeset/blue-actors-rule.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": minor
3+
---
4+
5+
Banner now supports onDismiss used when using variant critical.

‎packages/react/src/Banner/Banner.test.tsx

+8-5
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,14 @@ describe('Banner', () => {
169169
expect(onDismiss).toHaveBeenCalledTimes(3)
170170
})
171171

172-
it('should not support onDismiss when `variant="critical"`', () => {
173-
const onDismiss = jest.fn()
174-
render(<Banner title="test" description="test-description" onDismiss={onDismiss} variant="critical" />)
175-
expect(screen.queryByRole('button', {name: 'Dismiss banner'})).toBe(null)
176-
})
172+
it.each(['critical', 'info', 'success', 'upsell', 'warning'] as const)(
173+
'should support onDismiss for the %s variant',
174+
variant => {
175+
const onDismiss = jest.fn()
176+
render(<Banner title="test" description="test-description" onDismiss={onDismiss} variant={variant} />)
177+
expect(screen.queryByRole('button', {name: 'Dismiss banner'})).toBeInTheDocument()
178+
},
179+
)
177180

178181
it('should pass extra props onto the container element', () => {
179182
const {container} = render(<Banner title="test" data-testid="test" />)

‎packages/react/src/Banner/Banner.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {useMergedRefs} from '../internal/hooks/useMergedRefs'
77
import classes from './Banner.module.css'
88
import type {ForwardRefComponent as PolymorphicForwardRefComponent} from '../utils/polymorphic'
99

10-
type BannerVariant = 'critical' | 'info' | 'success' | 'upsell' | 'warning'
10+
export type BannerVariant = 'critical' | 'info' | 'success' | 'upsell' | 'warning'
1111

1212
export type BannerProps = React.ComponentPropsWithoutRef<'section'> & {
1313
/**
@@ -41,8 +41,6 @@ export type BannerProps = React.ComponentPropsWithoutRef<'section'> & {
4141
/**
4242
* Optionally provide a handler to be called when the banner is dismissed.
4343
* Providing this prop will show a dismiss button.
44-
*
45-
* Note: This is not available for critical banners.
4644
*/
4745
onDismiss?: () => void
4846

@@ -101,7 +99,7 @@ export const Banner = React.forwardRef<HTMLElement, BannerProps>(function Banner
10199
},
102100
forwardRef,
103101
) {
104-
const dismissible = variant !== 'critical' && onDismiss
102+
const dismissible = !!onDismiss
105103
const hasActions = primaryAction || secondaryAction
106104
const bannerRef = React.useRef<HTMLElement>(null)
107105
const ref = useMergedRefs(forwardRef, bannerRef)

0 commit comments

Comments
 (0)
Please sign in to comment.