kobaltedev / kobalte

A UI toolkit for building accessible web apps and design systems with SolidJS.
https://kobalte.dev
MIT License
1.22k stars 62 forks source link

Improve number fields behavior when formatted with a unit #379

Closed joshuafcole closed 4 months ago

joshuafcole commented 5 months ago

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:

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.

netlify[bot] commented 5 months ago

Deploy Preview for kobalte ready!

Name Link
Latest commit 691729f9fe385565a97477995b9d4a45549cf0f1
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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 4 months ago

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

joshuafcole commented 4 months ago

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

jer3m01 commented 4 months ago

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

jer3m01 commented 4 months ago

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

joshuafcole commented 4 months ago

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! :)