-
Notifications
You must be signed in to change notification settings - Fork 648
SelectPanel: Update SelectPanel to use modern ActionList #4794
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
Changes from 6 commits
9cee0a4
c7aa5de
40a0c45
344f6ce
fa5f5a6
3cd9ecc
0003e59
713b5ad
6fc7f2b
a246981
e209f47
26cddc1
b1199fb
b669cff
1012662
67dc5c9
c66feb5
4fbb3c5
2d5e2b2
cee7737
9c972c3
17e4ca8
26b6fe6
42c50c0
0d0004f
3ba9bc7
92ab9c2
7b3d5e6
1cf1e09
92303d0
4dc3b41
f673034
3a7d490
ab3ea9c
44ff862
46c94e6
ff8379b
9353d71
0a126ad
91cd5a3
40322c5
f0150e4
f72b9d4
85d0237
2eca9fa
c875223
02a6dc9
25c574a
5dc6adb
85e0bb4
0ee74e1
798008e
beca8db
14fd206
185eb17
318aa99
e9c523c
efd1216
cd9a931
619ff96
e3fe7b8
ebac341
0513474
2afa236
0f38bf4
f72aa55
6e9d706
0b57206
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,8 +8,8 @@ import Spinner from '../Spinner' | |
| import type {TextInputProps} from '../TextInput' | ||
| import TextInput from '../TextInput' | ||
| import {get} from '../constants' | ||
| import {ActionList} from '../deprecated/ActionList' | ||
| import type {GroupedListProps, ListPropsBase} from '../deprecated/ActionList/List' | ||
| import {ActionList} from '../ActionList' | ||
| import type {GroupedListProps, ListPropsBase, ItemInput} from '../deprecated/ActionList/List' | ||
| import {useFocusZone} from '../hooks/useFocusZone' | ||
| import {useId} from '../hooks/useId' | ||
| import {useProvidedRefOrCreate} from '../hooks/useProvidedRefOrCreate' | ||
|
|
@@ -18,6 +18,8 @@ import useScrollFlash from '../hooks/useScrollFlash' | |
| import {VisuallyHidden} from '../internal/components/VisuallyHidden' | ||
| import type {SxProp} from '../sx' | ||
|
|
||
| import {isValidElementType} from 'react-is' | ||
|
|
||
| const menuScrollMargins: ScrollIntoViewOptions = {startMargin: 0, endMargin: 8} | ||
|
|
||
| export interface FilteredActionListProps | ||
|
|
@@ -59,7 +61,7 @@ export function FilteredActionList({ | |
| ) | ||
|
|
||
| const scrollContainerRef = useRef<HTMLDivElement>(null) | ||
| const listContainerRef = useRef<HTMLDivElement>(null) | ||
| const listContainerRef = useRef<HTMLUListElement>(null) | ||
| const inputRef = useProvidedRefOrCreate<HTMLInputElement>(providedInputRef) | ||
| const activeDescendantRef = useRef<HTMLElement>() | ||
| const listId = useId() | ||
|
|
@@ -109,6 +111,61 @@ export function FilteredActionList({ | |
|
|
||
| useScrollFlash(scrollContainerRef) | ||
|
|
||
| function MappedActionList(item: ItemInput) { | ||
| const { | ||
| description, | ||
| descriptionVariant, | ||
| sx, | ||
| text, | ||
| variant, | ||
| disabled, | ||
| trailingVisual: TrailingVisual, | ||
|
||
| leadingVisual: LeadingVisual, | ||
| trailingText, | ||
| trailingIcon: TrailingIcon, | ||
| onAction, | ||
| selected, | ||
| } = item | ||
|
|
||
| return ( | ||
| <ActionList.Item | ||
| sx={sx} | ||
| role="option" | ||
| onSelect={(e: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>) => { | ||
| if (typeof onAction === 'function') | ||
| onAction(item, e as React.MouseEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>) | ||
| }} | ||
| selected={selected} | ||
| variant={variant} | ||
| disabled={disabled} | ||
| > | ||
| {LeadingVisual ? ( | ||
| <ActionList.LeadingVisual> | ||
| <LeadingVisual /> | ||
| </ActionList.LeadingVisual> | ||
| ) : null} | ||
| {text} | ||
| {description ? ( | ||
| <ActionList.Description variant={descriptionVariant}>{description}</ActionList.Description> | ||
| ) : null} | ||
| {TrailingVisual ? ( | ||
| <ActionList.TrailingVisual> | ||
| {typeof TrailingVisual !== 'string' && isValidElementType(TrailingVisual) ? ( | ||
| <TrailingVisual /> | ||
| ) : ( | ||
| TrailingVisual | ||
| )} | ||
| </ActionList.TrailingVisual> | ||
| ) : TrailingIcon || trailingText ? ( | ||
| <ActionList.TrailingVisual> | ||
| {trailingText} | ||
| {TrailingIcon && <TrailingIcon />} | ||
| </ActionList.TrailingVisual> | ||
| ) : null} | ||
| </ActionList.Item> | ||
| ) | ||
| } | ||
|
|
||
| return ( | ||
| <Box display="flex" flexDirection="column" overflow="hidden" sx={sx}> | ||
| <StyledHeader> | ||
|
|
@@ -134,7 +191,11 @@ export function FilteredActionList({ | |
| <Spinner /> | ||
| </Box> | ||
| ) : ( | ||
| <ActionList ref={listContainerRef} items={items} {...listProps} role="listbox" id={listId} /> | ||
| <ActionList ref={listContainerRef} {...listProps} role="listbox" id={listId}> | ||
| {items.map((item, index) => { | ||
| return <MappedActionList key={index} {...item} /> | ||
| })} | ||
| </ActionList> | ||
| )} | ||
| </Box> | ||
| </Box> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.