Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@mantine/core] MultiSelect: fix hoverOnSearchChange when creatable #4344

Merged
merged 2 commits into from
Jun 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/mantine-core/src/MultiSelect/MultiSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ export const MultiSelect = forwardRef<HTMLInputElement, MultiSelectProps>((props
disableSelectedItemFiltering,
});

if (isCreatable && shouldCreate(_searchValue, sortedData)) {
createLabel = getCreateLabel(_searchValue);
filteredData.push({ label: _searchValue, value: _searchValue, creatable: true });
}

const hovered = Math.min(_hovered, filteredData.length - 1);

const getNextIndex = (
Expand Down Expand Up @@ -572,11 +577,6 @@ export const MultiSelect = forwardRef<HTMLInputElement, MultiSelectProps>((props
}
};

if (isCreatable && shouldCreate(_searchValue, sortedData)) {
createLabel = getCreateLabel(_searchValue);
filteredData.push({ label: _searchValue, value: _searchValue, creatable: true });
}

const shouldRenderDropdown =
!readOnly && (filteredData.length > 0 ? dropdownOpened : dropdownOpened && !!nothingFound);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,24 @@ import { MultiSelect } from '@mantine/core';

function Demo() {
return (
<MultiSelect
data={['React', 'Angular', 'Svelte', 'Vue', 'Riot', 'Next.js', 'Blitz.js']}
label="Your favorite frameworks/libraries"
placeholder="Pick all that you like"
searchable
hoverOnSearchChange
/>
<>
<MultiSelect
data={['React', 'Angular', 'Svelte', 'Vue', 'Riot', 'Next.js', 'Blitz.js']}
label="Your favorite frameworks/libraries"
placeholder="Pick all that you like"
searchable
hoverOnSearchChange
/>
<MultiSelect
data={[]}
creatable
searchable
hoverOnSearchChange
label="[creatable]Your favorite frameworks/libraries"
placeholder="Pick all that you like"
getCreateLabel={(query) => \`+ Create \${query}\`}
/>
</>
);
}
`;
Expand All @@ -29,6 +40,15 @@ function Demo() {
searchable
hoverOnSearchChange
/>
<MultiSelect
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove it from the demo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

data={[]}
creatable
searchable
hoverOnSearchChange
label="[creatable]Your favorite frameworks/libraries"
placeholder="Pick all that you like"
getCreateLabel={(query) => `Add: ${query}`}
/>
</div>
);
}
Expand Down