You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`choices`| Required |`Object[]`| - | List of choices |
63
-
|`create`| Optional |`Element`|`-`| A React Element to render when users want to create a new choice |
64
-
|`createLabel`| Optional |`string`| - | The label used as hint to let users know they can create a new choice. Displayed when the filter is empty. |
65
-
|`createItemLabel`| Optional |`string`|`ra.action .create_item`| The label for the menu item allowing users to create a new choice. Used when the filter is not empty. |
66
-
|`debounce`| Optional |`number`|`250`| The delay to wait before calling the setFilter function injected when used in a ReferenceArray Input. |
67
-
|`emptyValue`| Optional |`any`|`''`| The value to use for the empty element |
68
-
|`filterToQuery`| Optional |`string` => `Object`|`q => ({ q })`| How to transform the searchText into a parameter for the data provider |
69
-
|`inputText`| Optional |`Function`|`-`| Required if `optionText` is a custom Component, this function must return the text displayed for the current selection. |
70
-
|`matchSuggestion`| Optional |`Function`|`-`| Required if `optionText` is a React element. Function returning a boolean indicating whether a choice matches the filter. `(filter, choice) => boolean`|
71
-
|`onChange`| Optional |`Function`|`-`| A function called with the new value, along with the selected records, when the input value changes |
72
-
|`onCreate`| Optional |`Function`|`-`| A function called with the current filter value when users choose to create a new choice. |
73
-
|`optionText`| Optional |`string`|`Function`|`Component`|`name`| Field name of record to display in the suggestion item or function which accepts the correct record as argument (`(record)=> {string}`) |
74
-
|`optionValue`| Optional |`string`|`id`| Field name of record containing the value to use as input value |
75
-
|`setFilter`| Optional |`Function`|`null`| A callback to inform the `searchText` has changed and new `choices` can be retrieved based on this `searchText`. Signature `searchText => void`. This function is automatically set up when using `ReferenceArray Input`. |
76
-
|`shouldRender Suggestions`| Optional |`Function`|`() => true`| A function that returns a `boolean` to determine whether or not suggestions are rendered. |
77
-
|`suggestionLimit`| Optional |`number`|`null`| Limits the numbers of suggestions that are shown in the dropdown list |
78
-
|`translateChoice`| Optional |`boolean`|`true`| Whether the choices should be translated |
|`choices`| Required |`Object[]`| - | List of choices |
63
+
|`create`| Optional |`Element`|`-`| A React Element to render when users want to create a new choice |
64
+
|`createLabel`| Optional |`string`|`ReactNode`| - | The label used as hint to let users know they can create a new choice. Displayed when the filter is empty. |
65
+
|`createItemLabel`| Optional |`string`|`(filter: string) => ReactNode`|`ra.action .create_item`| The label for the menu item allowing users to create a new choice. Used when the filter is not empty. |
66
+
|`debounce`| Optional |`number`|`250`| The delay to wait before calling the setFilter function injected when used in a ReferenceArray Input. |
67
+
|`emptyValue`| Optional |`any`|`''`| The value to use for the empty element |
68
+
|`filterToQuery`| Optional |`string` => `Object`|`q => ({ q })`| How to transform the searchText into a parameter for the data provider |
69
+
|`inputText`| Optional |`Function`|`-`| Required if `optionText` is a custom Component, this function must return the text displayed for the current selection. |
70
+
|`matchSuggestion`| Optional |`Function`|`-`| Required if `optionText` is a React element. Function returning a boolean indicating whether a choice matches the filter. `(filter, choice) => boolean`|
71
+
|`offline`| Optional |`ReactNode`| - | What to render when there is no network connectivity when fetching the choices |
72
+
|`onChange`| Optional |`Function`|`-`| A function called with the new value, along with the selected records, when the input value changes |
73
+
|`onCreate`| Optional |`Function`|`-`| A function called with the current filter value when users choose to create a new choice. |
74
+
|`optionText`| Optional |`string`|`Function`|`Component`|`name`| Field name of record to display in the suggestion item or function which accepts the correct record as argument (`(record)=> {string}`) |
75
+
|`optionValue`| Optional |`string`|`id`| Field name of record containing the value to use as input value |
76
+
|`setFilter`| Optional |`Function`|`null`| A callback to inform the `searchText` has changed and new `choices` can be retrieved based on this `searchText`. Signature `searchText => void`. This function is automatically set up when using `ReferenceArray Input`. |
77
+
|`shouldRender Suggestions`| Optional |`Function`|`() => true`| A function that returns a `boolean` to determine whether or not suggestions are rendered. |
78
+
|`suggestionLimit`| Optional |`number`|`null`| Limits the numbers of suggestions that are shown in the dropdown list |
79
+
|`translateChoice`| Optional |`boolean`|`true`| Whether the choices should be translated |
79
80
80
81
81
82
`<AutocompleteArrayInput>` also accepts the [common input props](./Inputs.md#common-input-props).
@@ -236,6 +237,21 @@ You can use the `createLabel` prop to render an additional (disabled) menu item
236
237
/>
237
238
```
238
239
240
+
You can also use any React node as the create label.
241
+
242
+
```jsx
243
+
<AutocompleteArrayInput
244
+
source="roles"
245
+
choices={choices}
246
+
create={<CreateRole />}
247
+
createLabel={
248
+
<Typography className="custom">
249
+
Start typing to create a new<strong>role</strong>
250
+
</Typography>
251
+
}
252
+
/>
253
+
```
254
+
239
255
## `createItemLabel`
240
256
241
257
If you set the `create` or `onCreate` prop, `<AutocompleteArrayInput>` lets users create new options. When the text entered by the user doesn't match any option, the input renders a "Create XXX" menu item at the bottom of the list.
@@ -253,6 +269,21 @@ Or, if you want to customize it just for this `<AutocompleteArrayInput>`, use th
253
269
/>
254
270
```
255
271
272
+
You can also define a function returning any rendered React node.
273
+
274
+
```jsx
275
+
<AutocompleteArrayInput
276
+
source="roles"
277
+
choices={choices}
278
+
create={<CreateRole />}
279
+
createItemLabel={item=> (
280
+
<Typography className="custom">
281
+
Create <Chip label={item} />
282
+
</Typography>
283
+
)}
284
+
/>
285
+
```
286
+
256
287
## `debounce`
257
288
258
289
When used inside a [`<ReferenceArrayInput>`](./ReferenceArrayInput.md), `<AutocompleteArrayInput>` will call `dataProvider.getList()` with the current input value as filter after a delay of 250ms. This is to avoid calling the API too often while users are typing their query.
`<AutocompleteArrayInput>` can display a custom message when it can't fetch the choices because there is no network connectivity, thanks to the `offline` prop.
0 commit comments