Repository navigation
feat(pagination): add editable input variant with page/row navigation mode - #4505
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsIcon (@astryxdesign/core) · View in Storybook
Pagination (@astryxdesign/core) · View in Storybook
Table (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: 1 accessibility violation(s) found — 1 serious. Icon - 1 issue(s)
Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
6c47b9f to
37b4619
Compare
|
Thanks for the steer — you're right, I had the intent backwards. Reworked to the full primitive:
First/last are gated behind |
cixzhang
left a comment
There was a problem hiding this comment.
This is a genuinely useful variant — an editable page/row box is something people ask for, and the row→page jump math is nicely handled. One direction I'd like to steer before we lock the public API: right now the labeling (Page [ n ] / N, Row [ n ]) is baked into fixed i18n strings, and navigateBy bundles the value's meaning, the layout, and the total-display into one enum. I'd rather give consumers full control over wording via a single formatLabel callback that receives the pagination state (page, pageCount, rowStart/rowEnd, totalItems) plus the pre-wired editable input node, and returns whatever label they want — "Page [n] / N", "3–4 of 200 rows", localized/RTL orderings, or a bare box. Your current default becomes the default formatLabel, so your own use case stays a one-liner (often zero config). I'd keep a small valueUnit: 'page' | 'row' just for what the number means (which drives onRowNavigate), and keep hasFirstLast and the new chevron icons as-is. Want me to sketch the PaginationState shape so we can align before you refactor? Really nice work on the keyboard/commit handling.
18d9f16 to
dd0bd15
Compare
| /** | ||
| * What the editable input's number *means* in the `input` variant. This drives | ||
| * navigation semantics only — the visible wording is controlled by | ||
| * `formatLabel`. | ||
| * - page: the value is a 1-based page number (default). | ||
| * - row: the value is a 1-based row index; committing it navigates to the page | ||
| * that contains that row (computed from pageSize) and reports the row via | ||
| * onRowNavigate. Requires totalItems to resolve rows to pages. | ||
| */ | ||
| export type PaginationValueUnit = 'page' | 'row'; |
There was a problem hiding this comment.
Can we have an open pageLabel instead?
There was a problem hiding this comment.
Done — replaced valueUnit with an open pageLabel?: string (defaults to the localized "Page"). A consumer wanting a "Row" reading just passes pageLabel="Row".
— on behalf of Freddy
| /** | ||
| * What the editable box's number means in the `input` variant. | ||
| * - page: the box holds a 1-based page number (default). | ||
| * - row: the box holds a 1-based row index; committing it navigates to the | ||
| * page containing that row (computed from pageSize) and fires | ||
| * onRowNavigate. Requires totalItems in `'row'` mode to resolve rows to | ||
| * pages. | ||
| * @default 'page' | ||
| */ | ||
| valueUnit?: PaginationValueUnit; |
There was a problem hiding this comment.
We have a format label so I think we can remove this.
There was a problem hiding this comment.
Removed — formatLabel (and the PaginationState it took) is gone, along with valueUnit. The label is now just the pageLabel noun + the editable box + / N.
— on behalf of Freddy
| /** | ||
| * Called with the committed 1-based row index when the `input` variant uses | ||
| * `valueUnit='row'`. Fires alongside onChange (which moves to the page | ||
| * containing that row). No-op in page mode. | ||
| */ | ||
| onRowNavigate?: (row: number) => void; |
There was a problem hiding this comment.
I think we can rely on page navigation in cases where we want the label to read "Row" instead.
There was a problem hiding this comment.
Done — dropped onRowNavigate and all the row→page math. Navigation now always flows through the existing onChange(page), same as every other variant; a "Row" label is just pageLabel="Row" on a page-navigated box. onChange is unchanged and no new callback was added.
— on behalf of Freddy
|
@cixzhang — all three simplified as suggested and pushed:
Net: the — on behalf of Freddy |
| input: { | ||
| width: sizeVars['--size-element-md'], | ||
| height: sizeVars['--size-element-md'], | ||
| textAlign: 'center', | ||
| boxSizing: 'border-box', | ||
| borderWidth: borderVars['--border-width'], | ||
| borderStyle: 'solid', | ||
| borderColor: { | ||
| default: colorVars['--color-border-emphasized'], | ||
| ':focus-visible': colorVars['--color-accent'], | ||
| }, | ||
| borderRadius: radiusVars['--radius-element'], | ||
| padding: 0, | ||
| fontFamily: typographyVars['--font-family-body'], | ||
| fontSize: { | ||
| default: typeScaleVars['--text-label-size'], | ||
| '@media (pointer: coarse)': `max(1rem, ${typeScaleVars['--text-label-size']})`, | ||
| }, | ||
| color: colorVars['--color-text-primary'], | ||
| backgroundColor: colorVars['--color-background-surface'], | ||
| boxShadow: { | ||
| default: 'none', | ||
| ':focus-visible': `inset 0px 0px 0px 2px ${colorVars['--color-accent-muted']}`, | ||
| }, | ||
| outline: 'none', | ||
| }, |
There was a problem hiding this comment.
I guess we should try to reuse NumberInput here
There was a problem hiding this comment.
Done — the editable box is now the core NumberInput (min={1}, max={totalPages}, isIntegerOnly, label-hidden). Dropped the hand-rolled parse/commit/clamp state since NumberInput owns typing, parsing, and range.
One behavior note worth calling out: NumberInput rejects and reverts an out-of-range entry rather than clamping to the nearest bound (the old bare input clamped 99 → 10). So committing an invalid page now snaps back to the current page instead of silently substituting a different one. I think that's the better UX (no surprise value swap), but flagging since it's a change — happy to revisit if you'd prefer clamping.
Also rebased clean onto main (was behind after the RTL refactor): the first/last chevrons now mirror via rtlStyles.mirror like prev/next, no useDirection.
— on behalf of Freddy
Adds an `input` variant to Pagination: an editable page-number box rendering `« ‹ [pageLabel] [ n ] / N › »` — first/last/prev/next controls around an editable box and the total page count. - The editable box is a core NumberInput bounded to [1, totalPages] with integer-only semantics, so range clamping and number parsing come for free instead of a hand-rolled bare <input>. - Navigation is page-based via the existing `onChange(page)`. - `pageLabel` is an open noun rendered before the box (defaults to the localized "Page"; pass e.g. `pageLabel="Row"` to relabel it). - First/last buttons are toggled by `hasFirstLast` (default true) and are omitted when the total is unknown (cursor/hasMore mode). - Prev/next and first/last chevrons mirror under RTL via the shared `rtlStyles.mirror` (CSS scaleX), consistent with the rest of the component — no JS direction read. - Registers `chevronsLeft`/`chevronsRight` icons for the first/last controls.
9abe5d0 to
dbad716
Compare
|
@cixzhang — heads-up on a change I pushed after your approval, so it doesn't slip in unseen. The
This is the composition-over-bespoke direction, so I think it's strictly better than the version you approved — but it does change the public theming surface (one fewer target) and swaps the box's a11y role ( If you're good with it, it's ready to land as-is. — on behalf of Freddy |
The icon-only carets exposed their label only to assistive tech (aria-label); sighted users got no hover affordance — the reason the EPS POC re-composed the control row. Forward the same localized, step-aware label to each caret Button via its existing tooltip prop, gated on the enabled state so a disabled caret keeps native disabled semantics (no focusable dead control). No new API.
|
Added one more thing to close the last gap vs the EPS POC wrapper ( Hover tooltips on the carets. The icon-only first/last/prev/next buttons exposed their label only to assistive tech (
No new API — rides entirely on Separately: while verifying this I found the caret icons render a few px above center (the RTL mirror wrapper dropped them out of the button's flex-centering) — that's a pre-existing bug from the mirror change, not this PR, so I fixed it independently in #4723 to keep this one focused. — on behalf of Freddy |

What
Adds an
inputpagination variant that renders the full editable-navigation primitive:« ‹ Page [ n ] / N › »« ‹ Row [ n ] › »(no/ Ntotal)where
«‹›»are first / prev / next / last. Typing a value in the box and committing (Enter or blur) jumps to it; invalid or empty entries revert.A navigation mode controls what the box represents:
navigateBy: 'page' | 'row'(default'page').'page'— the box holds a 1-based page number, clamped to1..totalPages, rendered asPage [ n ] / N.'row'— the box holds a 1-based row index, clamped to1..totalItems, rendered asRow [ n ](no total). Committing navigates to the page containing that row (ceil(row / pageSize)) and reports the row viaonRowNavigate(row)(fired alongsideonChange).The range readout you'd see to the right of a divider (
Showing 1–N of M) is intentionally not part of this primitive — that's app-level content the consumer composes next to the pager, not inside it.Why
#4248 asks for (1) an editable current-page control and (2) first/last buttons. The existing variants (
pages,count,compact,dots,none) display the position but don't let you type it or jump to the ends. This adds the complete control, and generalizes the box slightly so it can also drive row-level navigation (jump to a record in a long list).How
inputadded toPaginationVariantMap(extensible via module augmentation like the others), sovariant="input".Page/Row) and, in page mode, a trailing/ Ntotal. Both are i18n messages (@astryx.pagination.pageLabel,@astryx.pagination.rowLabel,@astryx.pagination.ofTotalPages). The label isaria-hidden— the input already carries its own accessible name via@astryx.pagination.goToPageInput.«/»double-chevron buttons flank prev/next, gated behind a newhasFirstLastprop (defaulttrue,inputvariant only). They're RTL-aware exactly like prev/next (viauseDirection()), disabled at the boundaries, and omitted when the page count is unknown (cursor/hasMorepagination, where there's no last page to jump to). aria-labels via@astryx.pagination.first/.last. Clicking first → page 1, last →computedTotalPages; both fire the existingpageAnnouncelive region.chevronsLeft/chevronsRight— added todefaultIcons.tsx, theIconNameunion inglobalIconRegistry.tsx, all seven theme icon registries (packages/themes/*/src/icons.tsx, mapped to lucide'sChevronsLeft/ChevronsRight) and their bundled CLI templates, plus the icon usage hints and Icon docs.NumberInput/DateInput): a local pending string shadows the committed value while typing; Enter and blur commit (parse → clamp → navigate), Escape discards, invalid/empty reverts.astryx-pagination-input,astryx-pagination-input-label,astryx-pagination-input-totalviathemeProps(..., {size}), documented inPagination.doc.mjstheming.targets. StyleX only, semantic tokens only.PaginationNavigateBy.Non-breaking
Defaults are unchanged (
variant='pages',navigateBy='page').hasFirstLastonly affects theinputvariant —pages/count/compact/dots/nonerender identically (covered by a non-regression test). New props are optional.Scope / relationship to #4248
This now implements request #1 (editable current-page control) and request #2 (first/last buttons). Request #3 (a configurable page label) is still out of scope — note this variant renders a fixed "Page"/"Row" label (localizable, but not consumer-configurable). A follow-up could add a label override prop if wanted.
Open questions for review (still a proposal)
inputreads clearly;editable/jumpare alternatives.navigateBynaming + shape — is'page' | 'row'the right axis, or should row navigation be a separate concern?onRowNavigate— fires alongsideonChange(page)(keepspage/onChangethe single source of truth). Should row mode instead suppressonChangeand only emit the row?hasFirstLastdefault — defaultingtruemakes the primitive match the design out of the box; is opt-out the right polarity, or should first/last be unconditional forinput?chevronsLeft/chevronsRight(lucide-style). Open to a different convention.Focus ring & default story (update)
box-shadowon:focus-visible(outline: none), matching every other bordered input. It previously drew a second, outset outline on top of the border (a doubled ring).formatLabel(Page [ n ] / N · showing rows X–Y of Z); the custom-label story shows a distinct compact example.Testing
Page [ n ] / N; row mode rendersRow [ n ]with no/ N; Enter/blur commit + clamp; revert on invalid/empty; first → page 1, last → last page; disabled at boundaries;hasFirstLast={false}hides them; first/last omitted when total unknown; double-chevron icons render; other variants gain no first/last; a11y names; announce fires; row mode maps rows→pages and clamps tototalItems.Variant: Input (page mode),Variant: Input (row mode),Variant: Input (no first/last), and anAll Variantsentry.Local gates green: full core suite (5486 passing), core + docs + storybook typecheck, ESLint (all changed files),
sync-exports --check,check-sync,check-changesets,token-docs --check, package-boundaries, full build, docsite generate + test.