Skip to content

Commit

Permalink
feat(SelectPanel): add support for announcements to SelectPanel.Loadi…
Browse files Browse the repository at this point in the history
…ng (#4407)

* feat(SelectPanel): add support for announcements to SelectPanel.Loading

* chore: add changeset

* chore: run format

* Update .changeset/rare-moose-destroy.md

Co-authored-by: Siddharth Kshetrapal <siddharthkp@github.com>

---------

Co-authored-by: Josh Black <joshblack@users.noreply.github.com>
Co-authored-by: Siddharth Kshetrapal <siddharthkp@github.com>
  • Loading branch information
3 people authored Mar 19, 2024
1 parent c090174 commit 4a7e44a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/rare-moose-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': minor
---

experimental/SelectPanel: Add support for announcements to SelectPanel.Loading
7 changes: 4 additions & 3 deletions packages/react/src/drafts/SelectPanel2/SelectPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {OverlayProps} from '../../Overlay/Overlay'
import {StyledOverlay, heightMap} from '../../Overlay/Overlay'
import InputLabel from '../../internal/components/InputLabel'
import {invariant} from '../../utils/invariant'
import {Status} from '../../internal/components/Status'
import {useResponsiveValue} from '../../hooks/useResponsiveValue'
import type {ResponsiveValue} from '../../hooks/useResponsiveValue'

Expand Down Expand Up @@ -569,9 +570,9 @@ const SelectPanelSecondaryAction: React.FC<SelectPanelSecondaryActionProps> = ({
else if (variant === 'checkbox') return <SecondaryCheckbox {...props} />
}

const SelectPanelLoading: React.FC<{children: string}> = ({children = 'Fetching items...'}) => {
const SelectPanelLoading = ({children = 'Fetching items...'}: React.PropsWithChildren) => {
return (
<Box
<Status
sx={{
display: 'flex',
flexDirection: 'column',
Expand All @@ -585,7 +586,7 @@ const SelectPanelLoading: React.FC<{children: string}> = ({children = 'Fetching
>
<Spinner size="medium" />
<Text sx={{fontSize: 1, color: 'fg.muted'}}>{children}</Text>
</Box>
</Status>
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {render} from '@testing-library/react'
import React from 'react'
import {SelectPanel} from '../'

describe('SelectPanel.Loading', () => {
it('should announce children as a polite message', () => {
render(<SelectPanel.Loading>test</SelectPanel.Loading>)

const liveRegion = document.querySelector('live-region')!
expect(liveRegion.getMessage('polite')).toBe('test')
})

it('should announce a default message when no children are provided', () => {
render(<SelectPanel.Loading />)

const liveRegion = document.querySelector('live-region')!
expect(liveRegion.getMessage('polite')).toBe('Fetching items...')
})
})

0 comments on commit 4a7e44a

Please sign in to comment.