Skip to content

Commit

Permalink
Merge pull request #1269 from core-ds/fix/select-select-all-empty
Browse files Browse the repository at this point in the history
fix(select): 'Select all' is hidden while options are empty
  • Loading branch information
hextion authored Jul 5, 2024
2 parents dfaf48a + a0161a0 commit 2c7ca00
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/curvy-eagles-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@alfalab/core-components-select': patch
---

Пункт 'Выбрать все' скрыт, когда список вариантов пуст
4 changes: 2 additions & 2 deletions packages/select/src/components/base-select/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ export const BaseSelect = forwardRef(
bottomAddons={
<React.Fragment>
{renderSearch()}
{bottomSheetProps?.bottomAddons}
{flatOptions.length > 0 && bottomSheetProps?.bottomAddons}
</React.Fragment>
}
containerProps={{
Expand Down Expand Up @@ -773,7 +773,7 @@ export const BaseSelect = forwardRef(
bottomAddons={
<React.Fragment>
{renderSearch()}
{modalHeaderProps?.bottomAddons}
{flatOptions.length > 0 && modalHeaderProps?.bottomAddons}
</React.Fragment>
}
>
Expand Down
9 changes: 6 additions & 3 deletions packages/select/src/presets/useSelectWithApply/hook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export function useSelectWithApply({
const groupAccessor = searchProps.groupAccessor ?? defaultGroupAccessor;
const filterGroup = searchProps.filterGroup ?? false;

const { flatOptions, selectedOptions } = useMemo(
const { flatOptions, filteredOptions, selectedOptions } = useMemo(
() =>
processOptions(
options,
Expand Down Expand Up @@ -177,8 +177,11 @@ export function useSelectWithApply({
}, [selectedOptions]);

const memoizedOptions = useMemo(
() => (showSelectAll ? [selectAllOption, ...options] : options),
[options, showSelectAll],
() =>
filteredOptions.length && showSelectAll
? [selectAllOption, ...filteredOptions]
: filteredOptions,
[filteredOptions, showSelectAll],
);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ export const OptionsListWithApply = forwardRef<HTMLDivElement, OptionsListWithAp
return (
<React.Fragment>
{header}
{showHeaderWithSelectAll && <Header {...headerProps} />}
{showHeaderWithSelectAll && flatOptions.length > 0 && (
<Header {...headerProps} />
)}
</React.Fragment>
);
};
Expand Down

0 comments on commit 2c7ca00

Please sign in to comment.