Skip to content

refactor(MultiSelector): rename formatTriggerCount to formatValue and widen it to the trigger line - #5377

Merged
cixzhang merged 2 commits into
mainfrom
multiselector-format-value
Aug 24, 2026
Merged

cixzhang merged 2 commits into
mainfrom
multiselector-format-value

Conversation

@cixzhang

@cixzhang cixzhang commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A builder who wants to control the text a component renders for its value finds a different prop name on every component they reach for:

component prop signature
NumberInput formatValue (value: number) => string
Slider formatValue (value: number) => string
ProgressBar formatValueLabel (value: number, max: number) => string
MultiSelector formatTriggerCount (count: number) => string

#4032 added the fourth spelling this morning. It has not shipped: git tag --contains b31b8a0b5d7 is empty and the published @astryxdesign/core is 0.4.7, which predates the merge. So fixing the name today costs nothing — no codemod, no deprecation window, no breaking changeset, just a patch. The moment it ships once, it is permanent public surface and this becomes a migration.

Change

formatTriggerCount → formatValue, and the callback now formats the whole trigger line rather than only the count.

formatValue?: (items: MultiSelectorSelectedItem[]) => string;  // {value: string; label: string}[]

Why items rather than a count. A prop named formatValue that only sees count cannot express what people actually want in the trigger — "Alice, Bob and 2 others", or a language whose plural rule depends on the items. The count survives as items.length, so nothing is lost against (count: number) => string. Handing over both the value and the resolved label is what makes it usable: values are opaque ids in real configs ({value: 'a', label: 'Apple'}), and labels are what the trigger renders — a caller who got only the values would have to re-resolve them against options, which the component already did just above. MultiSelectorSelectedItem is exported.

Which display modes it reaches. triggerDisplay="count" and "labels", both of which render a single text string. It is deliberately not used by "badges", which renders Badge elements rather than text; a string formatter there would have to either throw the badges away or be silently ignored, and neither is a good default for a mode whose whole point is the elements. That exclusion is stated in the JSDoc and in the docs, and there is a test that pins it. If someone wants a string trigger, "count"/"labels" is the mode for it.

A generic name that silently did nothing on two of three modes would be worse than the specific name was — this is what earns it.

Defaults are byte-identical when the prop is absent, which is the safety of the change: count still renders `${n} selected`, labels still renders A, B, C, +N, badges is untouched, and an empty selection still shows the placeholder without calling the formatter. All 111 existing MultiSelector tests pass unchanged, including the ones that assert those exact strings.

Not done, deliberately:

  • ProgressBar.formatValueLabel stays as it is. It is released, so renaming it costs a codemod and a deprecation cycle — a separate decision nobody has made. It remains the odd one out until someone makes it.
  • The ?? '${n} selected' fallback stays at the call site rather than becoming a real default parameter. With the prop now covering two modes the default output is mode-dependent (count → "3 selected", labels → "A, B, C, +N"), so a single default value cannot express it.

Test plan

  • vitest run packages/core/src/MultiSelector/MultiSelector.test.tsx — 111 passed. New: formatValue in count mode; the items argument carries values and resolved labels ({value: 'a', label: 'Apple'}); formatValue in labels mode; badges mode ignores it and still renders badges; an empty selection shows the placeholder and never calls the formatter.
  • pnpm -F @astryxdesign/core typecheck and typecheck:docs — both clean.
  • git grep -rn formatTriggerCount — no matches anywhere in the repo, including packages/cli/assets/templates/.
  • Docs updated in all three blocks of MultiSelector.doc.mjs (full, docsZh, docsDense); the zh block never had an entry for this prop, so one was added.

Changeset: patch, credited to @Kevinjohn, whose PR this refines.


One unrelated commit, because main is red. build-storybook fails on current main, not on this change: #3933 landed <Avatar size="small"> in Chat.stories.tsx:632 after #4140 replaced Avatar's named sizes with the abbreviated scale (xsm | sm | md | lg | xl), so pnpm -F @astryxdesign/storybook typecheck errors and blocks every PR branched off it. Fixed here as a separate commit ("small" → "sm") rather than left for someone else to hit. Happy to split it out if you would rather it landed on its own.

… widen it to the trigger line

formatValue now receives the selected items ({value, label}[]) and formats
the trigger for triggerDisplay 'count' and 'labels'; 'badges' renders
elements, so it is excluded. The prop is unreleased, so no codemod or
deprecation is needed. Defaults are unchanged when the prop is absent.
@vercel

vercel Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 24, 2026 1:28am

Request Review

@cixzhang
cixzhang enabled auto-merge (squash) August 24, 2026 01:08
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 24, 2026
…d size scale

#3933 landed a story with size="small" after #4140 replaced Avatar's named
sizes with the abbreviated scale, so build-storybook's typecheck fails on
main and blocks every PR based on it.
@cixzhang
cixzhang merged commit d895769 into main Aug 24, 2026
19 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

MultiSelector (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1506 -
Complexity N/A Very High (188) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.8KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

This branch was successfully deployed

1 active deployment
Preview — dcb50884 Deployed Aug 24, 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.

1 participant