Skip to content

Commit f70b916

Browse files
chrisrolfe198Chris Rolfe
andauthored
feat: extend ComboBox ListBox to allow rendering empty state (#577)
Co-authored-by: Chris Rolfe <chris.rolfe@free-now.com>
1 parent 03f283a commit f70b916

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/components/experimental/ComboBox/ComboBox.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {
33
ComboBox as BaseComboBox,
44
ComboBoxProps as BaseComboBoxProps,
55
ComboBoxStateContext,
6-
FieldError
6+
FieldError,
7+
ListBoxProps
78
} from 'react-aria-components';
89
import { useIsSSR } from 'react-aria';
910
import { useResizeObserver } from '@react-aria/utils';
@@ -45,6 +46,7 @@ interface ComboBoxProps<T extends Record<string, unknown>>
4546
Omit<BaseComboBoxProps<T>, 'children'>,
4647
React.RefAttributes<HTMLDivElement> {
4748
children: React.ReactNode | ((item: T) => React.ReactNode);
49+
renderEmptyState?: ListBoxProps<unknown>['renderEmptyState'];
4850
}
4951

5052
const ComboBoxInput = React.forwardRef<HTMLDivElement, ComboBoxFieldProps>(
@@ -97,6 +99,7 @@ function ComboBoxComponent<T extends Record<string, unknown>>(
9799
ariaStrings = defaultAriaStrings,
98100
errorMessage,
99101
description,
102+
renderEmptyState,
100103
...restProps
101104
} = props;
102105

@@ -132,7 +135,7 @@ function ComboBoxComponent<T extends Record<string, unknown>>(
132135
<Footer>{isInvalid ? <FieldError>{errorMessage}</FieldError> : description}</Footer>
133136
</Wrapper>
134137
<Popover triggerRef={triggerRef} style={{ '--trigger-width': menuWidth } as React.CSSProperties}>
135-
<ListBox>{children}</ListBox>
138+
<ListBox renderEmptyState={renderEmptyState}>{children}</ListBox>
136139
</Popover>
137140
</>
138141
)}

src/components/experimental/ComboBox/docs/ComboBox.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export const AsyncValues: StoryObj<typeof ComboBox<Character>> = {
7474
const [filterText, setFilterText] = React.useState('');
7575

7676
const list = useAsyncList<Character>({
77-
async load({ signal, cursor }) {
77+
async load() {
7878
const res = await fetch(`https://swapi.py4e.com/api/people/?search=${filterText}`);
7979
const json = await res.json();
8080

0 commit comments

Comments
 (0)