-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update <SelectInput>
to support an array of strings as choices
#10038
Conversation
@@ -130,6 +131,14 @@ describe('<SelectInput />', () => { | |||
expect(options.length).toEqual(6); | |||
expect(options[1].textContent).toEqual('Created'); | |||
}); | |||
|
|||
it('should accept strings as choices', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only tested SelectInput because the logic is shared by all selection inputs via useChoicesContext
.
@@ -4,14 +4,20 @@ import { useList } from '../../controller'; | |||
import { ChoicesContext, ChoicesContextValue } from './ChoicesContext'; | |||
|
|||
export const useChoicesContext = <ChoicesType extends RaRecord = RaRecord>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised this doesn't trigger a TS error as RaRecord
can't be a string
. I believe this is because ChoicesProps
in useChoices
accepts any[]
for choices
. This might be an issue later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't type the choices as users may pass anything and set the optionText
and optionValue
. It's never been an issue ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not restrict the ChoicesType
then but let's do that in another PR
packages/ra-ui-materialui/src/input/CheckboxGroupInput.stories.tsx
Outdated
Show resolved
Hide resolved
packages/ra-ui-materialui/src/input/AutocompleteArrayInput.stories.tsx
Outdated
Show resolved
Hide resolved
Co-authored-by: adrien guernier <adrien@marmelab.com>
<SelectInput>
to support an array of strings as choices
Problem
For
SelectInput
and other selection inputs, sometimes the list of options is simply an array of strings. Doing the conversion to an array of option objects isn't intuitive.Solution
Support string choices by default.
This concerns the following components:
SelectInput
SelectArrayInput
AutocompleteInput
AutocompleteArrayInput
RadioButtonGroupInput
CheckboxGroupInput