Skip to content

fix/year backspace clearing - #2100

Merged
huntabyte merged 4 commits into
huntabyte:mainfrom
shireenmne:fix/year-backspace-clearing
Aug 19, 2026
Merged

fix/year backspace clearing#2100
huntabyte merged 4 commits into
huntabyte:mainfrom
shireenmne:fix/year-backspace-clearing

Conversation

@shireenmne

@shireenmne shireenmne commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Overview

Fixes the DatePicker year-segment backspace behavior described in #2038.

This builds on the work started in #2046 by @joe-herbert, which correctly identified and fixed two of the three underlying issues:

  1. Backspacing the year segment down to a single character was clearing the entire date value instead of just the year.
  2. Focus was advancing to the next segment prematurely after a typo + backspace + retype sequence.

Both of those fixes are preserved here.

What changed from #2046

The zero-padding approach used in #handleYearBackspace used integer division (Math.floor(parseInt(prev) / 10)) and re-padded the result back to 4 digits. In practice this reintroduced a leading zero mid-edit that shouldn't appear until the field is blurred, e.g.:
"1980" → backspace → "0198" (expected "198")

The fix here replaces that with plain string slicing. Padding back to 4 digits on blur is handled separately by the existing onfocusout logic, which was untouched and already correct. This also brings the year segment's backspace behavior in line with how day/month already worked.

A small follow-on fix was also needed in #handleYearNumberKey: after backspacing partway through the year, retyping the missing digits wasn't triggering the auto-advance to the next segment, because the advance check only counted raw keystrokes since the last backspace rather than the resulting string length. Fixed by also checking str.length === 4.

CI

One check (Test / Test - Chromium) has intermittently failed in this PR's history on should close on outside click in select and combobox, and separately on a context-menu test, all via the same shared assertion helper (expectNotExists in src/tests/browser-utils.ts:82), all unrelated to date-field.svelte.ts. The date-field suite itself has passed cleanly on every run, including after this PR's changes. This looks like pre-existing flakiness in that shared helper, happy to open a separate issue with the failure pattern if useful, but wanted to flag it here rather than have it look connected to this change.

Credit

Thanks @Fardeen0-0 for flagging this issue and picking up where #2046 left off in identifying the CI failures

@changeset-bot

changeset-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9d0323b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
bits-ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor
built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
bits-ui ✅ Ready (View Log) Visit Preview 9d0323b

- Preserve year-segment focus after backspace correction
- Add browser coverage for first-digit correction
@huntabyte
huntabyte merged commit d131732 into huntabyte:main Aug 19, 2026
6 checks passed
@github-actions github-actions Bot mentioned this pull request Aug 19, 2026
dadezzz pushed a commit to dadezzz/events-cash-register that referenced this pull request Aug 24, 2026
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [bits-ui](https://github.com/huntabyte/bits-ui) | [`2.18.2` → `2.19.0`](https://renovatebot.com/diffs/npm/bits-ui/2.18.2/2.19.0) | ![age](https://developer.mend.io/api/mc/badges/age/npm/bits-ui/2.19.0?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/bits-ui/2.18.2/2.19.0?slim=true) |

---

### Release Notes

<details>
<summary>huntabyte/bits-ui (bits-ui)</summary>

### [`v2.19.0`](https://github.com/huntabyte/bits-ui/releases/tag/bits-ui%402.19.0)

[Compare Source](https://github.com/huntabyte/bits-ui/compare/bits-ui@2.18.2...bits-ui@2.19.0)

##### Minor Changes

- feat(Checkbox): pass `form` to the hidden input ([#&#8203;2089](huntabyte/bits-ui#2089))

##### Patch Changes

- fix(DateField): keep focus on the year while correcting its first digit ([#&#8203;2100](huntabyte/bits-ui#2100))

- fix(Tooltip): close `Tooltip.Trigger` on `pointerdown` for any pointer button so right/middle click dismiss the tooltip and cancel a pending delayed open ([#&#8203;2101](huntabyte/bits-ui#2101))

- fix(RadioGroup): don't select item on pointer-driven focus- [#&#8203;2098](huntabyte/bits-ui#2098) ([#&#8203;2098](huntabyte/bits-ui#2098))

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4zMS4wIiwidXBkYXRlZEluVmVyIjoiNDQuMzEuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->
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.

2 participants