Skip to content

Commit

Permalink
fix(SingleEntitySelectMenuItems): correctly position "Add New" in cas…
Browse files Browse the repository at this point in the history
…e of an "*end" positioned `dropdownPlacement`

- display is inverted when the `Placement` is at the `end`, following the `MultiRecordSelect` component design
- add a story to display the `end` placement
- pass down the `dropdownPlacement` prop in `SingleEntitySelect`
  • Loading branch information
nicolasrouanne committed Nov 13, 2024
1 parent d22bbc3 commit e638a9a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type SingleEntitySelectProps = {

export const SingleEntitySelect = ({
disableBackgroundBlur = false,
dropdownPlacement,
EmptyIcon,
emptyLabel,
excludedRelationRecordIds,
Expand Down Expand Up @@ -52,6 +53,7 @@ export const SingleEntitySelect = ({
>
<SingleEntitySelectMenuItemsWithSearch
{...{
dropdownPlacement,
EmptyIcon,
emptyLabel,
excludedRelationRecordIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@ export const SingleEntitySelectMenuItemsWithSearch = ({
});

const createNewButton = isDefined(onCreate) && (
<DropdownMenuItemsContainer>
<CreateNewButton
onClick={() => onCreate?.(relationPickerSearchFilter)}
LeftIcon={IconPlus}
text="Add New"
/>
</DropdownMenuItemsContainer>
<CreateNewButton
onClick={() => onCreate?.(relationPickerSearchFilter)}
LeftIcon={IconPlus}
text="Add New"
/>
);

const results = (
Expand Down Expand Up @@ -87,6 +85,10 @@ export const SingleEntitySelectMenuItemsWithSearch = ({
<>
{dropdownPlacement?.includes('end') && (
<>
<DropdownMenuItemsContainer>
{createNewButton}
</DropdownMenuItemsContainer>
{entities.entitiesToSelect.length > 0 && <DropdownMenuSeparator />}
{results}
<DropdownMenuSeparator />
</>
Expand All @@ -97,10 +99,12 @@ export const SingleEntitySelectMenuItemsWithSearch = ({
<>
<DropdownMenuSeparator />
{results}
{entities.entitiesToSelect.length > 0 && <DropdownMenuSeparator />}
<DropdownMenuItemsContainer>
{createNewButton}
</DropdownMenuItemsContainer>
</>
)}
{entities.entitiesToSelect.length > 0 && <DropdownMenuSeparator />}
{createNewButton}
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,7 @@ export const WithSearchFilter: Story = {
});
},
};

export const WithEndPlacement: Story = {
args: { dropdownPlacement: 'bottom-end' },
};

0 comments on commit e638a9a

Please sign in to comment.