question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Event is of type `any` in `onChange` property of `InputBase`

See original GitHub issue

What package has an issue

@mantine/core

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:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rtivitalcommented, Nov 4, 2022

That is one of the mysteries of TypeScript, I have no idea why it is required in some cases

1reaction
rtivitalcommented, Nov 3, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found