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

Improve number fields behavior when formatted with a unit #379

Merged

Conversation

joshuafcole
Copy link
Contributor

@joshuafcole joshuafcole commented Mar 31, 2024

The new NumberField component is awesome, but while using it with style: unit format options specified, I realized it's behavior diverges pretty significantly from the lovely behavior in in the react spectrum component it's based on. This PR brings it closer into line, though it's still not quite perfect.

To see the issue:

  • create a NumberField
  • specify the following format options:
  • attempt to type into the field:
    • a decimal number into the field
    • typos like alphabetical characters
    • anything into the unit segment
const formatOptions = {
    minimumFractionDigits: 0,
    maximumFractionDigits: 1,
    style: "unit",
    unit: "second",
    unitDisplay: "long"
};

Expected behavior: The NumberField should normalize the user's input into a valid format
Actual behavior: The displayed value is polluted until submission, at which point it'll do it's best to parse what's there and renormalize.

This PR confirms that the user's changes are still parsable before committing them, without getting in the way of deleting the contents of the field entirely. It generally makes the unit behave like ineditable text.

Note that this may be able to completely replace the allowedInput regex prop (and related machinery) which doesn't have an analog in the react-spectrum NumberField, but I didn't want to make that assumption without checking in first.

Copy link

netlify bot commented Mar 31, 2024

Deploy Preview for kobalte ready!

Name Link
🔨 Latest commit 691729f
🔍 Latest deploy log https://app.netlify.com/sites/kobalte/deploys/660e0d29c89a96000855db1a
😎 Deploy Preview https://deploy-preview-379--kobalte.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@joshuafcole
Copy link
Contributor Author

Sorry, just noticed the lint issues. Hopefully all addressed, though I couldn't figure out how to run the reporter locally to test (pnpx biome ci didn't report the found issues)

@jer3m01
Copy link
Member

jer3m01 commented Apr 6, 2024

You can run pnpm lint && pnpm format to format code. Then pnpm test to build and test.
If test works locally but not on here, it's flaky and needs to rerun on github.

Edit: Looks good! I need to finish another task then I'll have a look at merging this!

@joshuafcole
Copy link
Contributor Author

joshuafcole commented Apr 10, 2024

Thanks for the clarification! Not sure how I missed it first time around.

EDIT: Just noticed the failing tests -- I'm really not sure what happened there. It looks like all the NumberField related tests passed: https://github.com/kobaltedev/kobalte/actions/runs/8548307913/job/23525538904?pr=379#step:7:120

but several for TextField failed: https://github.com/kobaltedev/kobalte/actions/runs/8548307913/job/23525538904?pr=379#step:7:148

Is there anything you can think of here that might have led to that?

@joshuafcole
Copy link
Contributor Author

Following up to see if there's anything else I can do to help get this across the line.

@joshuafcole
Copy link
Contributor Author

Looks like after a re-run everything's green. Any remaining work for me here?

@jer3m01
Copy link
Member

jer3m01 commented Apr 29, 2024

Hey all good! Almost done with #381 then I'll be able to merge.

@jer3m01 jer3m01 merged commit 9be4b9f into kobaltedev:main May 2, 2024
6 checks passed
@jer3m01
Copy link
Member

jer3m01 commented May 2, 2024

Thanks for the PR! I'll try to replace allowedInput and only use this.

@joshuafcole
Copy link
Contributor Author

joshuafcole commented May 2, 2024

Awesome news, and congrats on the refactor! If there's anything I can help with feel free to @ ping, Kobalte's been a huge help to me! :)

@github-actions github-actions bot mentioned this pull request May 3, 2024
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

Successfully merging this pull request may close these issues.

None yet

2 participants