Skip to content
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

[TypeScript] Fix disableClearable prop on AutocompleteArrayInput #7763

Closed
lvernaillen opened this issue May 27, 2022 · 3 comments
Closed

[TypeScript] Fix disableClearable prop on AutocompleteArrayInput #7763

lvernaillen opened this issue May 27, 2022 · 3 comments

Comments

@lvernaillen
Copy link

What you were expecting:
Setting the disableClearable prop on AutocompleteArrayInput should be possible without any build error. It removes the cross icon and removes the ability to clear the autocomplete input.

What happened instead:
Build error occurs stating Type 'true' is not assignable to type 'false'.
image

Steps to reproduce:
Use your simple application sandbox.
https://codesandbox.io/s/github/marmelab/react-admin/tree/master/examples/simple?file=/src/posts/TagReferenceInput.tsx
Update src/posts/TagReferenceInput.tsx by adding the disableClearable as shown below and see the compiler warning when hovering over the red squiggles.

<ReferenceArrayInput {...props} perPage={5} filter={{ published }}>
    <AutocompleteArrayInput
        create={<CreateTag />}
        optionText={`name.${locale}`}
        disableClearable  // ADD THIS PROP -> Type 'true' is not assignable to type 'false'
    />
</ReferenceArrayInput>

Other information:
Setting the prop disableClearable does work on a regular AutocompleteInput component.
This can be checked by adding the disableClearable prop to AutocompleteInput in src/posts/PostEdit.tsx.

A workaround is to force any type as done below. However that shouldn't be needed. Simply setting disableClearable should work.

<ReferenceArrayInput {...props} perPage={5} filter={{ published }}>
    <AutocompleteArrayInput
        create={<CreateTag />}
        optionText={`name.${locale}`}
        disableClearable={true as any}  // ADD THIS PROP -> this workaround works
    />
</ReferenceArrayInput>

Environment

  • React-admin version: 4.1.0
  • Last version that did not exhibit the issue (if applicable):
  • React version: 17
  • Browser: Chrome version 101.0.4951.67
@djhi
Copy link
Collaborator

djhi commented May 30, 2022

Reproduced. Thanks!

@djhi djhi changed the title Setting disableClearable prop on AutocompleteArrayInput gives build error [TypeScript] Fix disableClearable prop on AutocompleteArrayInput Jun 1, 2022
JinParc pushed a commit to JinParc/react-admin that referenced this issue Oct 25, 2022
@ethembynkr
Copy link
Contributor

Same error exists in the AutocompleteInput component.

React-admin version: 4.16.19

@fzaninotto
Copy link
Member

@ethembynkr Can you please open a new issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants