Skip to content

DxcNumberInput calls onChange function with '' when "." character is entered #1660

Closed
@fredofm

Description

@fredofm

Describe the bug
Not sure if it's a bug or I'm doing something wrong with the component.

When you type:

  • "1," -> the component transform this value into "1". It can make sense because as you din't type the fractional part it will return the integer one.
  • "1." -> the component transforms this value into "". It can make sense but I would expect the same behaviour as "1,".

It's not a big thing but as I'm creating my own validations, the user will receive an error like "value is required" even if he enters a value like "1.".

To Reproduce

  1. Include a DxcNumberInput in your code, like:
() => {
  const [value, setValue] = useState("");
  const onChange = ({ value }) => {
    setValue(value);
  };
  const onBlur = ({ value }) => {
    setValue(value);
  };

  return (
    <DxcInset space="2rem">
      <DxcNumberInput
        label="Enter your age"
        value={value}
        onChange={onChange}
        onBlur={onBlur}
        optional={false}
        clearable={true}
      />
    </DxcInset>
  );
}
  1. Set a breakpoint in onChange function to check the received value.
  2. Enter "1." and check the received value.

Expected behaviour

I would expect:

  • Component will transform "1." value to "1", similar to the current behaviour when typing "1,".

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context

Using halstack-react version 9.1.0.

"@dxc-technology/halstack-react": "^9.1.0"

Add labels
Add any applicable label like the concerned components or the target version of the Design System where the bug has been found.

Metadata

Metadata

Assignees

Labels

help wantedExtra attention is needed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions