-
I want to allow custom values in a ComboBox. How can I trigger to take the input as a new entry? On a Keyboard I could take Enter"Key. Is there an event listening to Enter ? What would you suggest in terms of accessibility? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
Have you read this part of our docs? https://react-spectrum.adobe.com/react-aria/useComboBox.html#allow-custom-values |
Beta Was this translation helpful? Give feedback.
-
Of Course. But the docs do not answer my questions.
I have userInput as state. But how do I know that the user has finished entering data?? |
Beta Was this translation helpful? Give feedback.
-
That sounds great and works for me.
I am quite unexperienced with TypeScript, so I have one more question.
The SearchAutocompleteProps extent the CollectionBase<T> containing the prop children: CollectionChildren<T>.
I have a localState to collect the selected entries from the SearchAutocomplete.
` const [suggestions, setSuggestions] = useState<CollectionChildren<object>>([]);`
With this state I render the `TAGS`and filter the suggestiions with the following code:
```const addTagHandler = (tag: string) => {
setTags([...tags, tag]);
setSuggestions((prevSuggestions : CollectionChildren<object>) => {
return prevSuggestions.filter(suggestion => suggestion != tag)
})
}```
Unfortunately filter does not exist on prevSuggestions ☹. I assume that I could use one of the hooks from react-stately , but I would like to understand how this works
Von: Daniel Lu ***@***.***>
Datum: Dienstag, 27. September 2022 um 22:23
An: adobe/react-spectrum ***@***.***>
Cc: Thomas Lucas ***@***.***>, Author ***@***.***>
Betreff: Re: [adobe/react-spectrum] Using Allow custom values in ComboBox (Discussion #3555)
Well that really depends on what functionality you want to allow your SearchAutocomplete to support. Since you are creating your own SearchAutocomplete from the hooks, you can control what props are actually passed to the hooks. If you don't want to do too much customization, you could use SearchAutocompleteProps<https://github.com/adobe/react-spectrum/blob/main/packages/%40react-types/autocomplete/src/index.d.ts#L19> as a base for your props interface.
—
Reply to this email directly, view it on GitHub<#3555 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AB7INGEBKHBRZGT275RIQT3WANJTPANCNFSM6AAAAAAQVPAXH4>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Yes, you are right! Ok- now I have it. I tried to pass the options with the children prop and not with items.
Now my component works as expected 😊
Amazing Framework !!!!
Von: Daniel Lu ***@***.***>
Datum: Mittwoch, 28. September 2022 um 18:44
An: adobe/react-spectrum ***@***.***>
Cc: Thomas Lucas ***@***.***>, Author ***@***.***>
Betreff: Re: [adobe/react-spectrum] Using Allow custom values in ComboBox (Discussion #3555)
Just to clarify, the suggestions that you mentioned are the options you will display in the drop down? If so, I'd recommend performing your filtering like its done here<https://reactspectrum.blob.core.windows.net/reactspectrum/26f9662ffb90217c26f906397b1a67b3197e476d/docs/react-aria/useSearchAutocomplete.html#custom-filtering>, aka filtering/modifying the items list you provide to your SearchAutocomplete instead. No need to use the CollectionChildren themselves
—
Reply to this email directly, view it on GitHub<#3555 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AB7INGCTHXDO5U2XSLIQABLWARYVHANCNFSM6AAAAAAQVPAXH4>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
Just to clarify, the
suggestions
that you mentioned are the options you will display in the drop down? If so, I'd recommend performing your filtering like its done here, aka filtering/modifying the items list you provide to your SearchAutocomplete instead. No need to use the CollectionChildren themselves