Skip to content

Commit

Permalink
[@mantine/core] TagsInput: Improve clearable prop logic related to …
Browse files Browse the repository at this point in the history
…dropdown (#6115)
  • Loading branch information
rtivital committed May 10, 2024
1 parent be4b4ab commit 3cc0cd0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ export function Clearable() {
clearable
/>

<MultiSelect
placeholder="Searchable"
data={['React', 'Angular', 'Svelte']}
defaultValue={['React']}
clearable
searchable
mt="md"
/>

<MultiSelect
placeholder="Disabled"
data={['React', 'Angular', 'Svelte']}
Expand Down
9 changes: 7 additions & 2 deletions packages/@mantine/core/src/components/TagsInput/TagsInput.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useId, useUncontrolled } from '@mantine/hooks';
import { useRef } from 'react';
import { useId, useMergedRef, useUncontrolled } from '@mantine/hooks';
import {
BoxProps,
ElementProps,
Expand Down Expand Up @@ -193,6 +194,8 @@ export const TagsInput = factory<TagsInputFactory>((_props, ref) => {
const _id = useId(id);
const parsedData = getParsedComboboxData(data);
const optionsLockup = getOptionsLockup(parsedData);
const inputRef = useRef<HTMLInputElement>(null);
const _ref = useMergedRef(inputRef, ref);

const combobox = useCombobox({
opened: dropdownOpened,
Expand Down Expand Up @@ -329,6 +332,8 @@ export const TagsInput = factory<TagsInputFactory>((_props, ref) => {
onClear={() => {
setValue([]);
setSearchValue('');
inputRef.current?.focus();
combobox.openDropdown();
onClear?.();
}}
/>
Expand Down Expand Up @@ -394,7 +399,7 @@ export const TagsInput = factory<TagsInputFactory>((_props, ref) => {
<Combobox.EventsTarget autoComplete={autoComplete}>
<PillsInput.Field
{...rest}
ref={ref}
ref={_ref}
{...getStyles('inputField')}
unstyled={unstyled}
onKeyDown={handleInputKeydown}
Expand Down

0 comments on commit 3cc0cd0

Please sign in to comment.