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

Select Panel: Functional adjustments #4906

Merged
merged 83 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
9cee0a4
super wip
broccolinisoup Jul 30, 2024
c7aa5de
just use the actionlist component and revert the type updates
broccolinisoup Jul 30, 2024
40a0c45
Update packages/react/src/FilteredActionList/FilteredActionList.tsx
broccolinisoup Jul 30, 2024
344f6ce
Some more progress
broccolinisoup Jul 31, 2024
fa5f5a6
revert the type changes and cast it :/
broccolinisoup Jul 31, 2024
3cd9ecc
clean
broccolinisoup Jul 31, 2024
0003e59
wip
broccolinisoup Aug 2, 2024
713b5ad
wip wip
broccolinisoup Aug 5, 2024
6fc7f2b
add stories
broccolinisoup Aug 8, 2024
a246981
fix linting
broccolinisoup Aug 8, 2024
e209f47
add tests for groups
broccolinisoup Aug 8, 2024
26cddc1
Merge branch 'main' into select-panel-action-list
broccolinisoup Aug 8, 2024
b1199fb
Merge branch 'select-panel-story-and-tests' into select-panel-action-…
broccolinisoup Aug 8, 2024
b669cff
Map groups
broccolinisoup Aug 8, 2024
1012662
Merge branch 'main' into select-panel-story-and-tests
broccolinisoup Aug 12, 2024
67dc5c9
Update story names for e2e tests
broccolinisoup Aug 12, 2024
c66feb5
oops remove unintended file
broccolinisoup Aug 12, 2024
4fbb3c5
update story name
broccolinisoup Aug 12, 2024
2d5e2b2
same - update story name
broccolinisoup Aug 12, 2024
cee7737
disable animations
broccolinisoup Aug 12, 2024
9c972c3
test(vrt): update snapshots
broccolinisoup Aug 12, 2024
17e4ca8
Merge branch 'select-panel-story-and-tests' into select-panel-action-…
broccolinisoup Aug 12, 2024
26b6fe6
Update tests since new action list has different semantics for group …
broccolinisoup Aug 12, 2024
42c50c0
Merge branch 'main' into select-panel-action-list
broccolinisoup Aug 13, 2024
0d0004f
logging
broccolinisoup Aug 14, 2024
3ba9bc7
pass the rest
broccolinisoup Aug 14, 2024
92ab9c2
extract children and use before text
broccolinisoup Aug 14, 2024
7b3d5e6
remove logging
broccolinisoup Aug 14, 2024
1cf1e09
Merge branch 'main' into select-panel-action-list
siddharthkp Aug 20, 2024
92303d0
test(vrt): update snapshots
siddharthkp Aug 20, 2024
4dc3b41
add active styles to ActionList
siddharthkp Aug 21, 2024
f673034
rename component name to be clearer
siddharthkp Aug 21, 2024
3a7d490
remove variant full from examples
siddharthkp Aug 21, 2024
ab3ea9c
tiny clean up
siddharthkp Aug 21, 2024
44ff862
fix showItemDividers
siddharthkp Aug 21, 2024
46c94e6
another tiny cleanup
siddharthkp Aug 21, 2024
ff8379b
pull MappedActionListItem to make it stable
siddharthkp Aug 22, 2024
9353d71
Merge branch 'main' into select-panel-action-list
siddharthkp Aug 22, 2024
0a126ad
test(vrt): update snapshots
siddharthkp Aug 22, 2024
91cd5a3
show active styles only when used with keyboard
siddharthkp Aug 22, 2024
40322c5
backward compat: expose id as data-id
siddharthkp Aug 22, 2024
f0150e4
Merge branch 'select-panel-action-list' of github.com:primer/react in…
siddharthkp Aug 22, 2024
f72b9d4
update snapshots
siddharthkp Aug 22, 2024
85d0237
add story for long strings
siddharthkp Aug 26, 2024
2eca9fa
fishing for errors
siddharthkp Aug 26, 2024
c875223
backward compatibility for renderItem
siddharthkp Aug 26, 2024
02a6dc9
remove todo now
siddharthkp Aug 26, 2024
25c574a
add a feature flag
siddharthkp Aug 26, 2024
5dc6adb
clean up dual filter list setup
siddharthkp Aug 27, 2024
85e0bb4
run jests test with both states of feature flags
siddharthkp Aug 27, 2024
0ee74e1
refactor snapshot tests with scenarios
siddharthkp Aug 27, 2024
798008e
remove feature flag for main
siddharthkp Aug 27, 2024
beca8db
Merge branch 'main' into select-panel-action-list
siddharthkp Aug 27, 2024
14fd206
Merge branch 'selectpanel-prepare-scenarios' into select-panel-action…
siddharthkp Aug 27, 2024
185eb17
test(vrt): update snapshots
siddharthkp Aug 28, 2024
318aa99
add feature flag to e2e matrix
siddharthkp Aug 28, 2024
e9c523c
test(vrt): update snapshots
siddharthkp Aug 28, 2024
efd1216
backward compat: allow groupMetadata to be empty array
siddharthkp Aug 28, 2024
cd9a931
Merge branch 'select-panel-action-list' of github.com:primer/react in…
siddharthkp Aug 28, 2024
619ff96
Merge branch 'main' into select-panel-action-list
siddharthkp Aug 29, 2024
e3fe7b8
sigh newline
siddharthkp Aug 29, 2024
ebac341
Create sour-cooks-dress.md
siddharthkp Aug 30, 2024
0513474
Merge branch 'main' into select-panel-action-list
siddharthkp Aug 30, 2024
2afa236
copy SelectPanel snapshots from main
siddharthkp Sep 2, 2024
0f38bf4
remove unrelated changes in this PR
siddharthkp Sep 3, 2024
f72aa55
test(vrt): update snapshots
siddharthkp Sep 3, 2024
9d6ecdc
add more bindkeys
siddharthkp Sep 3, 2024
e33bc33
add for deprecated version as well
siddharthkp Sep 3, 2024
fef1c27
label listbox/ActionList by panel title
siddharthkp Sep 3, 2024
4b2f9c6
Create wicked-books-occur.md
siddharthkp Sep 3, 2024
d20fafb
remove Home and End
siddharthkp Sep 4, 2024
44cd938
add test for PageDown and PageUp
siddharthkp Sep 4, 2024
04439b5
update changeset
siddharthkp Sep 4, 2024
c4d7cab
active styles for both directly and indirectly
siddharthkp Sep 4, 2024
de4684c
add role=combobox
siddharthkp Sep 5, 2024
540ef9f
update snapshot
siddharthkp Sep 5, 2024
058bd56
Merge branch 'main' into select-panel--functional-adjustments-1
siddharthkp Sep 10, 2024
5f862ed
test(vrt): update snapshots
siddharthkp Sep 10, 2024
aab2b3d
remove features from deprecated version
siddharthkp Sep 11, 2024
3c9c6c5
Merge branch 'select-panel--functional-adjustments-1' of github.com:p…
siddharthkp Sep 11, 2024
5f9fdef
update test
siddharthkp Sep 11, 2024
b7a81e3
only use aria-labelledby when aria-label is not passed
siddharthkp Sep 11, 2024
dafe94e
remove combobox for this PR
siddharthkp Sep 11, 2024
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
7 changes: 7 additions & 0 deletions .changeset/wicked-books-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@primer/react": minor
---

SelectPanel: Support <kbd>PageDown</kbd> and <kbd>PageUp</kbd> for keyboard navigation

SelectPanel: Label `listbox` by the title of the panel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {ScrollIntoViewOptions} from '@primer/behaviors'
import {scrollIntoView} from '@primer/behaviors'
import {scrollIntoView, FocusKeys} from '@primer/behaviors'
import type {KeyboardEventHandler} from 'react'
import React, {useCallback, useEffect, useRef} from 'react'
import styled from 'styled-components'
Expand Down Expand Up @@ -86,6 +86,7 @@ export function FilteredActionList({
useFocusZone(
{
containerRef: listContainerRef,
bindKeys: FocusKeys.ArrowVertical | FocusKeys.PageUpDown,
focusOutBehavior: 'wrap',
focusableElementFilter: element => {
return !(element instanceof HTMLInputElement)
Expand Down
48 changes: 47 additions & 1 deletion packages/react/src/SelectPanel/SelectPanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const items: SelectPanelProps['items'] = [
},
]

function BasicSelectPanel() {
function BasicSelectPanel(passthroughProps: Record<string, unknown>) {
const [selected, setSelected] = React.useState<SelectPanelProps['items']>([])
const [filter, setFilter] = React.useState('')
const [open, setOpen] = React.useState(false)
Expand All @@ -51,6 +51,7 @@ function BasicSelectPanel() {
onOpenChange={isOpen => {
setOpen(isOpen)
}}
{...passthroughProps}
/>
</ThemeProvider>
)
Expand Down Expand Up @@ -200,6 +201,22 @@ for (const useModernActionList of [false, true]) {
expect(onOpenChange).toHaveBeenLastCalledWith(false, 'click-outside')
})

it('should label the list by title unless a aria-label is explicitly passed', async () => {
const user = userEvent.setup()

renderWithFlag(<BasicSelectPanel />, useModernActionList)
await user.click(screen.getByText('Select items'))
expect(screen.getByRole('listbox', {name: 'test title'})).toBeInTheDocument()
})

it('should label the list by aria-label when explicitly passed', async () => {
const user = userEvent.setup()

renderWithFlag(<BasicSelectPanel aria-label="Custom label" />, useModernActionList)
await user.click(screen.getByText('Select items'))
expect(screen.getByRole('listbox', {name: 'Custom label'})).toBeInTheDocument()
})

describe('selection', () => {
it('should select an active option when activated', async () => {
const user = userEvent.setup()
Expand Down Expand Up @@ -288,6 +305,35 @@ for (const useModernActionList of [false, true]) {
screen.getByRole('option', {name: 'item one'}).id,
)
})

it('should support navigating through items with PageDown and PageUp', async () => {
if (!useModernActionList) return // this feature is only enabled with feature flag on

const user = userEvent.setup()

renderWithFlag(<BasicSelectPanel />, useModernActionList)

await user.click(screen.getByText('Select items'))

// First item by default should be the active element
expect(document.activeElement!).toHaveAttribute(
'aria-activedescendant',
screen.getByRole('option', {name: 'item one'}).id,
)

await user.type(document.activeElement!, '{PageDown}')

expect(document.activeElement!).toHaveAttribute(
'aria-activedescendant',
screen.getByRole('option', {name: 'item three'}).id,
)

await user.type(document.activeElement!, '{PageUp}')
expect(document.activeElement!).toHaveAttribute(
'aria-activedescendant',
screen.getByRole('option', {name: 'item one'}).id,
)
})
})

describe('filtering', () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/react/src/SelectPanel/SelectPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ export function SelectPanel({
placeholderText={placeholderText}
{...listProps}
role="listbox"
// browsers give aria-labelledby precedence over aria-label so we need to make sure
// we don't accidentally override props.aria-label
aria-labelledby={listProps['aria-label'] ? undefined : titleId}
aria-multiselectable={isMultiSelectVariant(selected) ? 'true' : 'false'}
selectionVariant={isMultiSelectVariant(selected) ? 'multiple' : 'single'}
items={itemsToRender}
Expand Down
5 changes: 5 additions & 0 deletions packages/react/src/deprecated/ActionList/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export interface ListPropsBase {
*/
id?: string

/**
* aria-label to attach to the base DOM node of the list
*/
'aria-label'?: string

/**
* A `List`-level custom `Item` renderer. Every `Item` within this `List`
* without a `Group`-level or `Item`-level custom `Item` renderer will be
Expand Down
Loading