Skip to content

Commit

Permalink
[@mantine/core] PinInput: Fix updating controlled value to an empty s…
Browse files Browse the repository at this point in the history
…tring working incorrectly
  • Loading branch information
rtivital committed Feb 26, 2024
1 parent fc33874 commit 5f06ddd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/@mantine/core/src/components/PinInput/PinInput.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ export function OnComplete() {
);
}

export function ResetControlled() {
const [value, setValue] = useState('1234');

return (
<div style={{ padding: 40 }}>
<PinInput value={value} onChange={setValue} />
<Button onClick={() => setValue('')}>Reset</Button>
</div>
);
}

export function ReadOnly() {
return (
<div style={{ padding: 40 }}>
Expand Down
6 changes: 6 additions & 0 deletions packages/@mantine/core/src/components/PinInput/PinInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,12 @@ export const PinInput = factory<PinInputFactory>((props, ref) => {
}
}, [length, _value]);

useEffect(() => {
if (value === '') {
setValues(createPinArray(length ?? 0, value));
}
}, [value]);

return (
<>
<Group
Expand Down

0 comments on commit 5f06ddd

Please sign in to comment.