Mantle Combobox Item Text Migration Guide
A pick on Combobox.Item wrote the item's value into Combobox.Input. It now writes the text that the item's children show, and only text: the input is a plain text input, so the item's icons, avatars, badges, and other elements stay in the list. The text is what the children show, without their hidden and aria-hidden parts, such as a decorative icon or avatar. value stays the value that Combobox.Root holds and submits. A preset value or defaultValue, and a form reset, now show the same text, also on the server, where the input was empty before. An item whose children show its value, such as <Combobox.Item value="Apple" /> or <Combobox.Item value="Apple">Apple</Combobox.Item>, behaves as before.
TL;DR: For each Combobox.Item whose children show other text than its value: filter on the shown text, not on value; submit the picked value with name on Combobox.Root, not on Combobox.Input; delete the preventDefault() and inputValue code that only kept an ID out of the input; and, when the children show extra text that must not reach the input, control inputValue.
Codemod
Codemod: manual: which items show other text than their value, and what the app does with the input text, is a semantic question that no syntax rule can answer.
You are an agent migrating a codebase. Do this:
- Find each
Combobox.Itemwhose children show other text than itsvalue, such as<Combobox.Item value={user.id}>{user.name}</Combobox.Item>. Skip an item with no children, or with children that show itsvalue. - Find the filter of that combobox, the code that reads
inputValueoronInputValueChangeto choose the items. After a pick, the input holds the item's text. A filter that matches onlyvalue, such as an ID, now shows no options when the list opens again. Match the shown text, or the shown text and the value. - Find a
nameonCombobox.Inputin that combobox. The input now submits the shown text, not the value. MovenametoCombobox.Root, which submits the picked value. Keep it on the input only when the form must submit the typed text. - Find a
Combobox.ItemonClickthat callsevent.preventDefault()and then sets the value, the text, andopenitself, or aninputValuethat the app controls only to show a name for an ID value or a preset value. Delete that code: the pick and the preset value now show the name. Keep apreventDefault()for an item that must not pick, such as an action item. - Find an item whose children show text that must not reach the input, such as a status badge, an email, a "Join pool" label, or a domain's availability. Mark decorative parts
aria-hidden="true". When the text must still reach a screen reader, controlinputValueandonInputValueChangeand write the text yourself on a pick, fromonValueChange. - Find an item whose
onClickwrites a sentinel value into a field throughonInputValueChange, such as a "Random URL" item.onInputValueChangenow receives the shown text after the click. Write the sentinel fromonValueChange, or cancel the pick withevent.preventDefault()and set the field yourself. - In tests, assert the shown text on the input after a pick, a preset
value, or a form reset. Assert the picked value throughonValueChangeor the form data. - After editing, run the project's formatter, linter, type checker, and tests.
Why the children? The user picks what they read. An input that shows an ID after the user picked a name, or an empty input for a preset value, made each app with ID values keep its own text state. Radix
Select.Valueshows the selected item's children for the same reason.
Before → after
An ID value with a name
Edge cases & gotchas
- A function child can render text only while it is highlighted, so a pick writes its
value. An item that a component of your own renders, and an item that is not loaded yet, showvaluefor a preset value. - For a preset value, mantle reads the elements that you wrote. A component with no
childrenprop, such asCombobox.ItemValueor an icon, adds no text there. - The input stays one line. Long text ends with an ellipsis.
How to verify
- Pick an item whose children differ from its
value. The input shows the children's text, and the form submits the value. - Open the list again. The filter shows the picked item.
- Render the form with a preset value. The input shows the item's text before any script runs.