Skip to content

Commit

Permalink
[@mantine/core] Select: Fix search value not changing when component …
Browse files Browse the repository at this point in the history
…value is controlled (#4915)
  • Loading branch information
wuifdesign authored Oct 1, 2023
1 parent a878762 commit 88ab079
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/mantine-core/src/components/Select/Select.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ export function ControlledSearch() {
);
}

export function SearchControlledValue() {
return (
<div style={{ padding: 40 }}>
<Select
value="React"
data={['React', 'Angular', 'Svelte']}
placeholder="Select something"
searchable
/>
</div>
);
}

export function AllowDeselectFalse() {
return (
<div style={{ padding: 40 }}>
Expand Down
6 changes: 3 additions & 3 deletions src/mantine-core/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react';
import React, { useEffect, useMemo } from 'react';
import { useId, useUncontrolled } from '@mantine/hooks';
import {
BoxProps,
Expand Down Expand Up @@ -135,8 +135,8 @@ export const Select = factory<SelectFactory>((_props, ref) => {
...others
} = props;

const parsedData = getParsedComboboxData(data);
const optionsLockup = getOptionsLockup(parsedData);
const parsedData = useMemo(() => getParsedComboboxData(data), [data]);
const optionsLockup = useMemo(() => getOptionsLockup(parsedData), [parsedData]);
const _id = useId(id);

const [_value, setValue] = useUncontrolled({
Expand Down

0 comments on commit 88ab079

Please sign in to comment.