Repository navigation
refactor(MultiSelector): rename formatTriggerCount to formatValue and widen it to the trigger line - #5377
Merged
Conversation
… 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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
cixzhang
enabled auto-merge (squash)
August 24, 2026 01:08
Contributor
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsMultiSelector (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
formatValue(value: number) => stringformatValue(value: number) => stringformatValueLabel(value: number, max: number) => stringformatTriggerCount(count: number) => string#4032 added the fourth spelling this morning. It has not shipped:
git tag --contains b31b8a0b5d7is empty and the published@astryxdesign/coreis 0.4.7, which predates the merge. So fixing the name today costs nothing — no codemod, no deprecation window, no breaking changeset, just apatch. 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.Why items rather than a count. A prop named
formatValuethat only seescountcannot 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 asitems.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 againstoptions, which the component already did just above.MultiSelectorSelectedItemis 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 rendersBadgeelements 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:
countstill renders`${n} selected`,labelsstill rendersA, B, C, +N,badgesis 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.formatValueLabelstays 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.?? '${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:formatValuein count mode; the items argument carries values and resolved labels ({value: 'a', label: 'Apple'});formatValuein 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 typecheckandtypecheck:docs— both clean.git grep -rn formatTriggerCount— no matches anywhere in the repo, includingpackages/cli/assets/templates/.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-storybookfails on current main, not on this change: #3933 landed<Avatar size="small">inChat.stories.tsx:632after #4140 replaced Avatar's named sizes with the abbreviated scale (xsm | sm | md | lg | xl), sopnpm -F @astryxdesign/storybook typecheckerrors 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.