Skip to content

Commit

Permalink
[@mantine/core] NumberInput: Fix startValue nor working if min is…
Browse files Browse the repository at this point in the history
… set (#5308)
  • Loading branch information
rtivital committed Dec 4, 2023
1 parent 1ab6aab commit 0fd6499
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ export function Usage() {
);
}

export function MinWithStartValue() {
return (
<div style={{ padding: 40 }}>
<NumberInput label="with min" min={-1000} startValue={20} />
</div>
);
}

export function OnChangeValue() {
const [value, setValue] = useState<number | string>(345);
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export const NumberInput = factory<NumberInputFactory>((_props, ref) => {

const increment = () => {
if (typeof _value !== 'number' || Number.isNaN(_value)) {
setValue(min ?? clamp(startValue!, min, max));
setValue(clamp(startValue!, min, max));
} else if (max !== undefined) {
setValue(_value + step! <= max ? _value + step! : max);
} else {
Expand All @@ -249,7 +249,7 @@ export const NumberInput = factory<NumberInputFactory>((_props, ref) => {

const decrement = () => {
if (typeof _value !== 'number' || Number.isNaN(_value)) {
setValue(max ?? clamp(startValue!, min, max));
setValue(clamp(startValue!, min, max));
} else {
setValue(getDecrementedValue({ value: _value, min, step, allowNegative }));
}
Expand Down

0 comments on commit 0fd6499

Please sign in to comment.