Skip to content

Commit d78387c

Browse files
author
Matthias Prost
authored
fix(UnitInput): value to change in controlled (#5022)
1 parent 96685a2 commit d78387c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

.changeset/warm-wombats-kiss.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ultraviolet/ui": patch
3+
---
4+
5+
Fix `<UnitInput />` value not updating when changing in controlled

packages/ui/src/components/UnitInput/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import styled from '@emotion/styled'
22
import { AlertCircleIcon, CheckCircleIcon } from '@ultraviolet/icons'
33
import type { ComponentProps, InputHTMLAttributes, ReactNode } from 'react'
4-
import { useId, useMemo, useState } from 'react'
4+
import { useEffect, useId, useMemo, useState } from 'react'
55
import { Label } from '../Label'
66
import { SelectInputV2 } from '../SelectInputV2'
77
import type { OptionType } from '../SelectInputV2/types'
@@ -275,6 +275,12 @@ export const UnitInput = ({
275275
return 'neutral'
276276
}, [error, success])
277277

278+
useEffect(() => {
279+
if (value !== undefined) {
280+
setVal(value)
281+
}
282+
}, [value])
283+
278284
return (
279285
<Stack gap={0.5}>
280286
{label || labelInformation ? (

0 commit comments

Comments
 (0)