Skip to content

Commit eee2647

Browse files
committed
fix(NumberInput): side buttons not working on re-render (#5527)
1 parent 295650b commit eee2647

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

.changeset/eight-wings-add.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 `<NumberInput />` disabled button not working on re-render

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ export const NumberInput = forwardRef(
298298
[localRef, min, onChange],
299299
)
300300

301-
const isMinusDisabled = useMemo(() => {
301+
const isMinusDisabled = useCallback(() => {
302302
if (!localRef?.current?.value || localRef?.current?.value === '') {
303303
return false
304304
}
@@ -313,7 +313,7 @@ export const NumberInput = forwardRef(
313313
return Number.isNaN(numericValue) || numericValue <= minValue
314314
}, [localRef?.current?.value, min])
315315

316-
const isPlusDisabled = useMemo(() => {
316+
const isPlusDisabled = useCallback(() => {
317317
if (!localRef?.current?.value || localRef?.current?.value === '') {
318318
return false
319319
}
@@ -344,6 +344,10 @@ export const NumberInput = forwardRef(
344344
if (value !== undefined) {
345345
inputValue =
346346
value !== null && typeof value === 'number' ? value.toString() : ''
347+
348+
if (localRef.current) {
349+
localRef.current.value = inputValue
350+
}
347351
}
348352

349353
return (
@@ -377,7 +381,7 @@ export const NumberInput = forwardRef(
377381
>
378382
<Button
379383
aria-label="minus"
380-
disabled={disabled || readOnly || isMinusDisabled}
384+
disabled={disabled || readOnly || isMinusDisabled()}
381385
onClick={onClickSideButton('down')}
382386
sentiment="neutral"
383387
size={size === 'small' ? 'xsmall' : 'small'}
@@ -451,7 +455,7 @@ export const NumberInput = forwardRef(
451455
>
452456
<Button
453457
aria-label="plus"
454-
disabled={disabled || readOnly || isPlusDisabled}
458+
disabled={disabled || readOnly || isPlusDisabled()}
455459
onClick={onClickSideButton('up')}
456460
sentiment="neutral"
457461
size={size === 'small' ? 'xsmall' : 'small'}

0 commit comments

Comments
 (0)