Skip to content

Commit

Permalink
Merge pull request #10442 from marmelab/fix-autocomplete-focus-create
Browse files Browse the repository at this point in the history
[Doc] Explain `openOnFocus` in `<AutocompleteInput>` with StrictMode
  • Loading branch information
slax57 authored Jan 13, 2025
2 parents 0577a60 + 95fa20f commit 4bdf7b5
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/AutocompleteArrayInput.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ const CreateRole = () => {
```
{% endraw %}

**Tip**: In development with `React.StrictMode`, you may run into an issue where the `<AutocompleteArrayInput>` menu reopens after clicking the create item when the [`openOnFocus`](https://mui.com/material-ui/api/autocomplete/#autocomplete-prop-openOnFocus) prop is set to `true` which is the default with React-admin. If that bothers you, set the `openOnFocus` prop to `false`.

If you just need to ask users for a single string to create the new option, you can use [the `onCreate` prop](#oncreate) instead.

If you're in a `<ReferenceArrayInput>` or `<ReferenceManyToManyInput>`, the `handleSubmit` will need to create a new record in the related resource. Check the [Creating New Choices](#creating-new-choices) for an example.
Expand Down
2 changes: 2 additions & 0 deletions docs/AutocompleteInput.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ const CreateCategory = () => {
```
{% endraw %}

**Tip**: In development with `React.StrictMode`, you may run into an issue where the `<AutocompleteInput>` menu reopens after clicking the create item when the [`openOnFocus`](https://mui.com/material-ui/api/autocomplete/#autocomplete-prop-openOnFocus) prop is set to `true` which is the default with React-admin. If that bothers you, set the `openOnFocus` prop to `false`.

If you want to customize the label of the "Create XXX" option, use [the `createItemLabel` prop](#createitemlabel).

If you just need to ask users for a single string to create the new option, you can use [the `onCreate` prop](#oncreate) instead.
Expand Down
1 change: 1 addition & 0 deletions examples/simple/src/comments/CommentEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ const CommentEdit = props => {
return title.includes(filterValue);
}}
optionText={<OptionRenderer />}
openOnFocus={false}
inputText={inputText}
/>
</ReferenceInput>
Expand Down
1 change: 1 addition & 0 deletions examples/simple/src/posts/PostCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ const PostCreate = () => {
<AutocompleteInput
label="User"
create={<CreateUser />}
openOnFocus={false}
/>
</ReferenceInput>
<FormDataConsumer>
Expand Down
1 change: 1 addition & 0 deletions examples/simple/src/posts/TagReferenceInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const TagReferenceInput = ({
<AutocompleteArrayInput
create={<CreateTag />}
optionText={`name.${locale}`}
openOnFocus={false}
/>
</ReferenceArrayInput>
<Button
Expand Down

0 comments on commit 4bdf7b5

Please sign in to comment.