Versions:
@progress/kendo-react-inputs: 9.4.0
@progress/kendo-react-form: 9.4.0
(all @progress dependencies at 9.4.0)
When using NumericTextBox outside of a KendoReact Form FieldWrapper, the min attribute seems to behave as expected. For the following case:
<NumericTextBox label={'Non-Form NumericTextBox Input'} min={0} />
the NumericTextBox blur event seems to set the input value to 0, as expected.
However, when used as part of a form wrapper, as follows:
<Form
render={(props: FormRenderProps) => {
return (
<Field
name="numericInputField"
label={'Form NumericTextBox Input'}
component={FormNumericTextBox}
min={0}
/>
);
}}
/>
export const FormNumericTextBox = (fieldRenderProps: FieldRenderProps) => {
const {
validationMessage,
touched,
label,
id,
valid,
disabled,
hint,
onBlur,
customProp,
required,
onChange,
min,
max,
...others
} = fieldRenderProps;
const showValidationMessage: string | false | null =
touched && validationMessage;
const showHint: boolean = !showValidationMessage && hint;
const hintId: string = showHint ? `${id}_hint` : '';
const errorId: string = showValidationMessage ? `${id}_error` : '';
/*
Temporary workaround. Kendo React does not remove negative sign when changing input value from negative to zero.
*/
const customOnChange = (event: NumericTextBoxChangeEvent) => {
if (min === 0 && event.value && event.value < min) {
onChange({ ...event, value: 1 });
onChange({ ...event, value: min });
} else {
onChange({ ...event });
}
};
return (
<FieldWrapper>
<NumericTextBox
ariaDescribedBy={`${hintId} ${errorId}`}
valid={valid}
id={id}
disabled={disabled}
onBlur={customProp?.customOnBlur}
required={true}
onChange={onChange}
min={min}
max={max}
label={label}
{...others}
/>
{showHint && <Hint id={hintId}>{hint}</Hint>}
{showValidationMessage && <Error id={errorId}>{validationMessage}</Error>}
</FieldWrapper>
);
};
In this case, when we set the value to a negative number, the blur event seems set the value to 0, but the negative sign (-) remains.
For convenient reproduction of this behavior, I have written up the following StackBlitz demo: https://stackblitz.com/edit/react-ts-sy4etxrp
Please let me know whether or not this is a bug, or if we need to do something differently besides using the included customOnChange as a temporary workaround.