Skip to content

fix(Tokenizer): place the caret after the last token - #7922

Merged
imdreamrunner merged 3 commits into
mainfrom
fix/tokenizer-caret-flow
Oct 23, 2026
Merged

imdreamrunner merged 3 commits into
mainfrom
fix/tokenizer-caret-flow

Conversation

@kentonquatman

@kentonquatman kentonquatman commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

#7375 has merged; this branch is rebased onto main and now holds only its own three commits: place the caret after the last token, its changeset wording, and keep a read-only field from taking the caret's room.

User impact

Anyone who focuses a Tokenizer or a PowerSearch that already has tokens. With an empty query, the text cursor blinks at the far end of the first row. Once tokens wrap, that is a different row from the last token, and in a filled first row it lands on top of a token. People expect the cursor where the next token goes: right after the last one.

Problem and solution fit

  1. Why does it happen? With tokens present and an empty query, the input is an absolutely positioned, end-aligned overlay across the first token row (added in #6057). An empty input paints its caret at its alignment edge, so it sits at that row's inline end.
  2. Why does it hurt? The caret is the only sign of where typing will go, and it points away from the last token.
  3. Why does that matter? In a field with several rows, a person cannot tell where their text will land until it appears.

#6057 took the empty input out of flow so its 40px minimum editing width could not wrap onto a blank row by itself. This keeps that guarantee in flow instead. The input follows the last token, and while the query is empty it asks only for what it needs:

  • Blurred, or read-only (a disabled field with a disabledMessage stays focusable): no room at all (no inset, and a negative margin cancels the column gap), so a full row never grows a blank one. This is fix(Tokenizer): avoid blank trailing input row #6057's guarantee.
  • Focused and editable: only its text inset, so the caret sits 9px after the last token on its row, exactly where the first typed character appears.
  • Typing: unchanged, the ordinary 40px editing width. With less than 44px left on the row (40px plus the 4px gap), the first keystroke moves the text to a new row.

Expected behavior and authority

Smallest restoration

Everything is in Tokenizer's compact input style. The overlay's absolute position, insets, width calculation, end alignment and per-size vertical centering go away. The empty state becomes a growing flex item with no basis, and only the blurred or read-only state drops its inset and cancels the gap. The focused empty input fills the rest of its row, so the space after the last token is still a direct click target. No prop, type, theme target or token changes.

Two width bands are left, both where the last row has almost no room:

  • Less than 9px left: focusing moves the caret to the start of a new row, so the field grows a row while focused, as wrapped text would. The alternative, reserving the inset even while blurred, gives fields at those widths a permanent blank row at rest, which fix(Tokenizer): avoid blank trailing input row #6057 removed.
  • 9px to 44px left: the caret sits after the last token, and the first keystroke moves the text to a new row, because typing keeps the 40px editing width.

Evidence

Real Chromium, Storybook, 2× scale.

  • Reproduction before the change (main + fix(Tokenizer): wrap tokens before the clear-all lane #7375): in all 17 Tokenizer and PowerSearch states probed, the focused caret sat at the first row's inline end. With wrapped tokens it was on a different row from the last token. For example, Pre-selected Items at 200px: caret on row 1, last token on row 2. PowerSearch Many Filters: caret on row 1, last token on row 3.
  • Result after the change: in all of them the caret is 9px after the last token, on its row. That holds for LTR and RTL; sm, md and lg; with a start icon, end content or a result count; and in both overflow modes. No field height changes, focused or blurred. With 44px or more left on the row, typed text starts exactly where the caret was. With 9px to 44px left, the first keystroke moves it to a new row; below 9px, focusing does. Both edges were measured with 3px to 50px left, LTR and RTL.
  • Read-only: a disabled field with a disabledMessage stays focusable, but read-only. Before the last commit, with 3px left on the last row, Tab grew Disabled With Message from 32px to 55px, adding a blank row where nothing can be typed (Tokenizer and PowerSearch, LTR and RTL). It now stays 32px, and the disabled-reason tooltip still appears.
  • Representative unchanged path: an empty field with no tokens, the input at maxEntries or collapsed by an overflow mode, and the typed state keep their styles. fix(Tokenizer): wrap tokens before the clear-all lane #7375's 22 end-lane Chromium cases and the Token remove-target contract pass on top of this change.
  • Regression proof: the new "Caret placement" story's play function joins the story play guard, in LTR and RTL. It fails on the pre-fix code ("The caret is not on the last token's row: caret y 56.00, last token 71.00–95.00"). It also fails on a variant without the blurred no-room rule ("With 3px left on the row, the resting field grew from 32.00 to 55.00"). A third case, focusing a read-only field with 3px left, fails without the read-only rule ("With 3px left on the row, focusing a read-only field grew it from 32.00 to 55.00").
  • Near-full Token Row: in CI, with the fonts its fixture is tuned to, both directions pass. Locally, with macOS fonts, its own "nearly full" precondition fails on main as well, so I replayed its assertions at narrower widths, from 33px down to 1.2px left on the row, in LTR and RTL with a coarse pointer. They pass. Below about 1px no input pixel is left to hit-test, which only a row filled to the pixel produces.

Preview: Caret placement (RTL) and PowerSearch Many Filters. Click into a field to see the caret.

Not verified: Safari and Firefox.

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

  • pnpm vitest run packages/core/src/Tokenizer packages/core/src/PowerSearch packages/core/src/Typeahead packages/core/src/__tests__/BusyOwnerAnnouncement.test.tsx: 16 files, 583 tests pass.
  • pnpm -F @astryxdesign/core typecheck; strict ESLint and Prettier on the changed files; pnpm check:changesets, check:sync and check:repo.
  • TokenizerEndLane and TokenRemoveTarget Chromium specs against pnpm storybook:build: all pass.
  • Caret placement play function: passes in LTR and RTL, and fails on all three mutations above. It and the read-only check also pass on a production pnpm storybook:build.
  • CI: every check passes, including the story play guard (Near-full Token Row and Caret placement, LTR and RTL) and visual regression (no Tokenizer or PowerSearch shot changed).

@vercel

vercel Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Oct 23, 2026 9:25pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 22, 2026
@astracat-bot

astracat-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🔄 In progress (for maintainers only) Oct 23, 2026, 9:26 PM UTC

@github-actions github-actions Bot added the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Oct 22, 2026
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

Previews ready: Storybook and Sandbox were built with this PR's docsite. CI evidence will be added when available.

View Storybook for this PR · View Sandbox for this PR

@kentonquatman
kentonquatman marked this pull request as ready for review October 22, 2026 16:18

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The caret fix works: with tokens and an empty query, the focused Tokenizer and PowerSearch caret now sits right after the last token on its row, in LTR and RTL. Approval waits on an engineering owner of the input-fields contract deciding whether the idle Spinner slot this branch carries from #7375 (about 22px held on every token row at rest, so a search never moves rows) is the reserve FR1 and FR7 call for, or the unexplained space FR2 rules out. Separately, please reword the caret changeset: when the last row has between 9px and about 44px left, the first keystroke wraps the text to a new row, so the cursor is not always where typed text starts.

[Automated review]

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The caret fix works: with tokens and an empty query, the focused Tokenizer and PowerSearch caret now sits right after the last token on its row, in LTR and RTL, and the reworded changeset matches what happens. Approval still waits on an engineering owner of the input-fields contract deciding whether the idle Spinner slot carried from #7375 (about 22px held on every token row at rest, so a search never moves rows) is the reserve FR1 and FR7 call for or the unexplained space FR2 rules out. Separately, please keep a read-only input from taking the caret's room: on the Disabled With Message story with under 9px left after the last token, Tab now grows the field a blank row (32px to 55px), because the no-room rule in inputCompact keys on :not(:focus) alone. The red pr-a11y job runs a spec that main gained after this branch's merge base, so it should clear on a rebase.

[Automated review]

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The caret fix works: with tokens and an empty query, the focused Tokenizer and PowerSearch caret now sits right after the last token on its row, in LTR and RTL, and a disabled field with a disabledMessage now keeps its height under keyboard focus. Approval still waits on an engineering owner of the input-fields contract deciding whether the idle Spinner slot carried from #7375 (22px held on every token row at rest, so a search never moves rows) is the reserve FR1 and FR7 call for, or the unexplained space FR2 rules out. Nothing else is needed in the code on this branch; if that decision changes #7375, re-carry its new version here. Please also refresh the description, which still lists six carried commits and says only the blurred state drops its inset.

[Automated review]

An empty query's input was an absolutely positioned, end-aligned overlay on the first token row, so the caret blinked at the far end of the first row, even when the tokens wrapped below it. The input now follows the last token in flow, so the caret sits where typed text will start. Blurred, the empty input claims no room, so a full row never grows a blank one; focused, it claims only its text inset and starts a new row when the last one has no room for the caret.
A disabled field with a disabledMessage stays focusable but read-only. Keyed on focus alone, the empty input claimed the caret's inset when such a field was focused, so with less than that left on the last row, Tab grew the field a blank row where nothing can be typed. The no-room rule now also holds while the input is read-only.

@imdreamrunner imdreamrunner left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving at this head. #7375 has merged; this branch is rebased onto main with only its own three commits, unchanged. The idle Spinner slot question CodeBunny raised was settled by merging #7375 as it is.

@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Oct 23, 2026
@imdreamrunner
imdreamrunner merged commit ee74c18 into main Oct 23, 2026
69 checks passed
@kentonquatman
kentonquatman deleted the fix/tokenizer-caret-flow branch October 23, 2026 22:10
ejhammond added a commit that referenced this pull request Oct 24, 2026
…g tokens and blank rows (#8249)

Add two PowerSearch stories whose play functions the story play guard now
runs in Chromium:

- Default filters beside the search input (and its RTL twin): filter tokens
  that reach past the field's center must not overlap the search input, and
  its center must hit-test as the input and focus it on press.
- Token row when resting styles win: for each resting declaration of the
  empty search input that an empty-query rule overrides, force the resting
  value to win (as an app's own unlayered StyleX output does when it emits
  the same atomic class) and require the input to stay on the token row
  with no change in field height.

Both fail on the layout before #7922, where the empty input was an
absolutely positioned overlay under the tokens, and pass on main.

This branch was successfully deployed

1 active deployment
Preview — b93fff8c Deployed Oct 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants