Replies: 1 comment 2 replies
-
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
We're building a design system on top of React Aria Components and are excited about the new multi-select ComboBox support in v1.16.0. We've successfully implemented the basic rendering using
selectionMode="multiple"withComboBoxValueandTagGroupto display selected items as tags — this all works great.However, we're running into issues when trying to use the multi-select ComboBox as a proper form field with validation. We'd love guidance from the team on the intended patterns.
We've now dug through the published
v1.16.0source and confirmed a few details, which we've summarized below so this discussion can stay concrete.For context, our design-system wrapper already composes the control in the same general way as the docs example: React Aria
ComboBox+Input+ popover/listbox +ComboBoxValue+TagGroup. So far, these issues do not appear to come from replacingInputwith a custom field implementation.Questions
1.
isRequiredvalidationWhen
isRequiredis set on a multi-select ComboBox inside a<Form>, submitting with items selected still triggers a required validation error.What we found: The
requiredattribute is set on the visible text<input>, but in multi-select mode the input text is always empty (selections are rendered as tags viaComboBoxValue). So the nativevalueMissingconstraint fires even when items are selected.Additionally,
useComboBoxStatepassesnullas the validation value whendisplayValueis an empty array (line ~353 ofuseComboBoxState.ts):This causes
useFormValidationStateto skip thevalidatefunction entirely (if (!validate || value == null) { return null; }), so custom validation can't catch the empty case either.Question: Is there a recommended way to use
isRequiredwith a multi-select ComboBox? Should we expect this to work out of the box, or is validation for multi-select still in progress?2. Custom validation (
validateprop)Given the null-skip behavior above, the
validatefunction is never called when zero items are selected. It does get called when items are selected, so we can validate "at least N items" when N > 0, but not "at least 1 item."Question: Is there a recommended pattern for custom validation with multi-select ComboBox? For example, enforcing minimum/maximum selection counts?
3. Server-side validation
We use React Aria's server validation pattern (
validationErrorson<Form>) for our form components.What we found:
ComboBoxappears to render one hidden input per selected key whennameis set andformValue="key"is used. When no items are selected, it renders a single hidden input with an empty string. This suggests multi-select submission should useformData.getAll(name)rather thanformData.get(name).useFormValidationStatealso appears to look up server errors byname, even for ComboBox.Question: Is this the intended submission/validation model for multi-select ComboBox? If so, should
validationErrorsbe expected to work out of the box withnamein the multi-select case, and should consumers always usegetAll(name)server-side?4. Fully controlled mode (
inputValue+value)When we control both
inputValueandvalue, the input text is always blank after selecting an item (which makes sense for multi-select — you wouldn't want the input to show a single selected item's text). But we want to confirm this is the intended behavior.Question: In fully controlled multi-select mode, is
inputValueexpected to remain empty / be cleared after each selection? Is there anything we need to handle differently compared to single-select fully controlled mode?5. Async data + validation coupling
In the async case,
itemsusually reflect only the current query. After selecting an item, many implementations clearinputValue, which can immediately empty the fetched collection. At that point, the field may still have selected keys and should be considered valid, but the visible input text is empty and the current option list may also be empty.This seems to reinforce that validation for multi-select should be based on the selected keys, not the input text or the currently loaded async collection.
Question: Is that the intended model for async multi-select as well? If the selected item objects are no longer present in the current async collection after the query changes, should consumers keep their own cache for rendering tags and validation UI, or is ComboBox expected to preserve enough selected item data internally?
Additional finding:
ComboBoxValue+TagGroupwith async dataOne related gotcha we hit:
ComboBoxValue's render prop gives back the selected item values, butTagGroupexpects items with stable keys for its collection. If the selected item objects don't include anidproperty themselves, passingselectedItemsdirectly toTagGroupcan fail with:Question: Is passing
selectedItemsdirectly toTagGrouponly expected to work when each selected item object already includes its ownid/key property? Or is there another recommended pattern for the async case?Environment
react-aria-components: 1.16.0react-aria: 3.47.0react-stately: 3.45.0react: 19.2.3Reproduction
Here's a minimal example that demonstrates the
isRequiredissue:Steps to reproduce:
Thank you for any guidance! The multi-select ComboBox feature is exactly what we needed, and we'd love to fully integrate it into our form system.
Beta Was this translation helpful? Give feedback.
All reactions