Skip to content

Commit

Permalink
fix combobox's example to allow a custom empty state
Browse files Browse the repository at this point in the history
  • Loading branch information
alexasselin008 committed Jan 8, 2025
1 parent 65cebc2 commit a4921a5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion apps/docs/content/components/pickers/ComboBox.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ A combo box can overridde the default [useFilter](https://react-spectrum.adobe.c

### Allow Empty Collection

A combo box can be rendered with an empty collection.
A combo box can be rendered with an empty collection. If you want the popover to open with a custom message, you can use the `renderEmptyState` prop within the `listBoxProps` prop.

<Example src="ComboBox/docs/allowEmptyCollection" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export default function Example() {
<ComboBox
allowsEmptyCollection
label="Roles"
listBoxProps={{
renderEmptyState: () => "No roles found"
}}
>
{[]}
</ComboBox>
Expand Down
8 changes: 6 additions & 2 deletions packages/components/src/ListBox/src/ListBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { HeaderContext } from "../../Header/index.ts";
import { useLocalizedString } from "../../i18n/index.ts";
import { ListBoxSectionContext } from "../../ListBoxSection/index.ts";
import { Text, type TextSize } from "../../typography/Text/index.ts";
import { composeClassnameRenderProps, cssModule, isFunction, type SizeAdapter, SlotProvider } from "../../utils/index.ts";
import { ClearContainerSlots, composeClassnameRenderProps, cssModule, isFunction, type SizeAdapter, SlotProvider } from "../../utils/index.ts";

import { ListBoxContext } from "./ListBoxContext.ts";
import { ListBoxItem, type ListBoxItemProps, type ListBoxItemSize, type SelectionIndicator } from "./ListBoxItem.tsx";
Expand Down Expand Up @@ -140,7 +140,11 @@ function ListBox<T extends object>(props: ListBoxProps<T>, ref: ForwardedRef<HTM
result = renderEmptyState(renderProps);

if (result) {
return <Text className={emptyItemClassNames} size={ListBoxToTextSizeAdapter[size]}>{result}</Text>;
return (
<ClearContainerSlots>
<Text className={emptyItemClassNames} size={ListBoxToTextSizeAdapter[size]}>{result}</Text>
</ClearContainerSlots>
);
}
}

Expand Down

0 comments on commit a4921a5

Please sign in to comment.