Skip to content

NumberControl: introduce string as a type for the value prop #45949

Closed as not planned

Description

@ciampo

The value prop in NumberControl hasn't been yet typed, since it sits in a difficult spot: should it be a number or a string ?

After debating, we reached the conclusion that it should be a string:

  • native HTML input elements deal with strings, afterall;
  • controlled components usually pass '' to represent an empty value (they can't pass undefined, since that would make the component uncontrolled).

Since currently NumberControl's value is typed as number | string, here's the plan of action:

  • Wrap up TypeScript migration of stories and tests (NumberControl: refactor styles/tests/stories to TypeScript, replace fireEvent with user-event #45990)
  • Rewrite the internals in NumberControl to remove as much as possible the duality of the number|string types, and instead assume that string will be the main type (NumberControl: tidy up and fix types around value prop #45982)
    • In the process, we may want to extract some basic utilities outside of each single components (number to string / string to number conversions), and move them to the shared utils folder.
    • If needed, add unit tests to make sure that both string and number values for the value prop are handled correctly
  • Find and update all derived components to use string instead of number. If possible, keep iterating up the chain of derived components, until only string is used
    • UnitControl
    • RangeControl
    • AnglePickerControl
    • ...
  • When all usages are migrated to string, deprecated the number type for value — starting from the "leaves" derived components, and walking backwards all the way towards NumberControl. The code handling the number case will left around for backward-compat.

Activity

  1. self-assigned this
    on Nov 21, 2022
  2. added
    [Type] Enhancement
    [Package] Components
    [Type] Code Quality
    on Nov 21, 2022
  3. ciampo commented on Sep 3, 2026

    @ciampo
    ContributorAuthor

    Closing as not planned. Making changes to NumberControl without causing backwards-compatibility issues has proved tricky over the years, and our efforts are now focused on the @wordpress/ui package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

[Package] Components[Type] Code Quality[Type] Enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions