Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextInput number type is not compatible with HTML step attribute #1836

Open
guyo13 opened this issue Oct 28, 2023 · 2 comments
Open

TextInput number type is not compatible with HTML step attribute #1836

guyo13 opened this issue Oct 28, 2023 · 2 comments

Comments

@guyo13
Copy link

guyo13 commented Oct 28, 2023

The onInput and onChange event handlers inside TextInput component call a parse function which converts the string value into a Number before being dispatched.

  function parse(raw) {
    if ($$restProps.type !== "number") return raw;
    return raw != "" ? Number(raw) : null;
  }

  /** @type {(e: Event) => void} */
  const onInput = (e) => {
    value = parse(e.target.value);
    dispatch("input", value);
  };

  /** @type {(e: Event) => void} */
  const onChange = (e) => {
    dispatch("change", parse(e.target.value));
  };

This behaviour breaks the step and pattern attributes from being used along with number inputs.

Suggested solution: Remove the parse function.

@SimpleProgrammingAU
Copy link
Contributor

For number inputs, use the NumberInput component. I wouldn't think the intention is for TextInput to be used with type="number".

@kennethklee
Copy link

The NumberInput component does not behave well with numbers like 1.1. Using TextInput with type=number is the only workaround.

Refers to #1873

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants