Skip to content

Commit

Permalink
[Picker] Fix empty state (#11915)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyledurand authored Apr 19, 2024
1 parent 3326581 commit 828995c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/flat-berries-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': patch
---

Fixed Picker empty state
47 changes: 26 additions & 21 deletions polaris-react/src/components/Picker/Picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export function Picker({
[updateText, listboxProps, allowMultiple, handleClose, activeItems],
);

const showList = options.length > 0 || query !== '';
const firstSelectedOption = reactChildrenText(
options.find((option) => option.value === activeItems?.[0])?.children,
);
Expand Down Expand Up @@ -232,6 +233,7 @@ export function Picker({
paddingInline="200"
borderBlockEndWidth="025"
borderColor="border"
minHeight={showList ? undefined : '58px'}
>
<ComboboxTextFieldContext.Provider value={textFieldContextValue}>
<SearchField
Expand All @@ -248,27 +250,30 @@ export function Picker({
</ComboboxTextFieldContext.Provider>
</Box>
) : null}

<ComboboxListboxContext.Provider value={listboxContextValue}>
<ComboboxListboxOptionContext.Provider
value={listboxOptionContextValue}
>
<Box paddingBlock="200">
<Listbox {...listboxProps} onSelect={handleSelect}>
{filteredOptions.current?.map((option) => (
<Listbox.Option
key={option.value}
selected={activeItems.some((item) => item === option.value)}
{...option}
/>
))}
{addAction && query !== '' && !queryMatchesExistingOption ? (
<Listbox.Action {...addAction} value={query} />
) : null}
</Listbox>
</Box>
</ComboboxListboxOptionContext.Provider>
</ComboboxListboxContext.Provider>
{showList && (
<ComboboxListboxContext.Provider value={listboxContextValue}>
<ComboboxListboxOptionContext.Provider
value={listboxOptionContextValue}
>
<Box paddingBlock="200">
<Listbox {...listboxProps} onSelect={handleSelect}>
{filteredOptions.current?.map((option) => (
<Listbox.Option
key={option.value}
selected={activeItems.some(
(item) => item === option.value,
)}
{...option}
/>
))}
{addAction && query !== '' && !queryMatchesExistingOption ? (
<Listbox.Action {...addAction} value={query} />
) : null}
</Listbox>
</Box>
</ComboboxListboxOptionContext.Provider>
</ComboboxListboxContext.Provider>
)}
</Popover.Pane>
</Popover>
);
Expand Down

0 comments on commit 828995c

Please sign in to comment.