Event is of type `any` in `onChange` property of `InputBase`
See original GitHub issueWhat package has an issue
Describe the bug
The onChange
property of the Input
and InputBase
component seems to be incorrectly typed, since the following happens:
import { InputBase, TextInput } from "@mantine/core";
export default function MyComponent() {
return (
<div>
{/* Event is of type 'any' */}
<InputBase onChange={(event) => console.log(event)} />
{/* Event is of the expected type */}
<TextInput onChange={(event) => console.log(event)} />
</div>
);
}
What version of @mantine/hooks page do you have in package.json?
^5.6.3
If possible, please include a link to a codesandbox with the reproduced problem
https://codesandbox.io/s/modern-resonance-ksqkx4?file=/src/MyComponent.tsx
Do you know how to fix the issue
Yes
Are you willing to participate in fixing this issue and create a pull request with the fix
Yes
Possible fix
This is more of a workaround than an actual fix, but the following module augmentation fixes the issue:
// mantine.d.ts
import type { InputBaseProps as MantineInputBaseProps } from '@mantine/core';
import type { ChangeEventHandler } from 'react';
interface InputBaseProps extends MantineInputBaseProps {
onChange?: ChangeEventHandler<HTMLInputElement> | undefined;
}
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to handle onChange in Typescript - reactjs - Stack Overflow
The function handleChangeDate(e: React.ChangeEvent<any>) in the code below works, but I get warnings because I use the type any . Which other ...
Read more >material-ui/TextField onChange does not allow for ... - GitHub
A potential fix would be to change the type of onChange to a function that allows any args in any order: { (...args:...
Read more >InputBase API - Material UI - MUI
API reference docs for the React InputBase component. ... defaultValue, any ... Notice that the first argument (event) might be undefined. onChange, func....
Read more >How to Identify Different Inputs with One Onchange Handler
The onChange event watches for changes in an input field. Every time the user types something into the field, the onChange event is...
Read more >Input field change event not triggered? - SAP Community
Hi all i have a input and on change event i am doing certain functionality. Scenario:User inputs 123 in the input field and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That is one of the mysteries of TypeScript, I have no idea why it is required in some cases
InputBase is a polymorphic component, it cannot usually pick up correct types information if you do not provide generic type – https://codesandbox.io/s/loving-thunder-1py1v1?file=/src/MyComponent.tsx