reactstrap
reactstrap copied to clipboard
Input component 'multiple' flag doesnt update onChange event type
- components:
Input - reactstrap version
#8.5.1 - import method
umd/csj/es - react version
#17.0.2 - bootstrap version
#4.5.2
What is happening?
I am creating an input component, making use of the multiple flag. I've created an onChange handler that is expecting an event as type ChangeEvent<HTMLSelectElement>, so I can query event.target.selectedOptions. However, I get a ts compaint that the event type is actually ChangeEvent<HTMLInputElement>, I assume because the Input event type is static, regardless of the flags.
What should be happening?
The input component should change the onChange event type to ChangeEvent<HTMLSelectElement> when the multiple flag is used.
Steps to reproduce issue
- Create a form with an Input, and use the
multipleflag. - Add an event handler to it, with the handler expecting the type
ChangeEvent<HTMLSelectElement>
Error message in console
Type 'HTMLInputElement' is missing the following properties from type 'HTMLSelectElement': length, options, selectedIndex, selectedOptions, and 4 more.
Code
<Input
id={name}
invalid={invalid}
type={"select"}
multiple
onChange={(e: ChangeEvent<HTMLSelectElement>) => handleChange(e)}
>
//_______
const handleChange = (event: ChangeEvent<HTMLSelectElement>) => {
alert(event.target.selectedOptions);
};
Can I work on this?
@Spectre-ak Of course! PRs are welcome. Here are our contributing guidelines.