reactstrap icon indicating copy to clipboard operation
reactstrap copied to clipboard

Input component 'multiple' flag doesnt update onChange event type

Open SamKomesarook opened this issue 4 years ago • 2 comments

  • 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

  1. Create a form with an Input, and use the multiple flag.
  2. 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);
  };

SamKomesarook avatar Sep 15 '21 01:09 SamKomesarook

Can I work on this?

Spectre-ak avatar Oct 01 '21 18:10 Spectre-ak

@Spectre-ak Of course! PRs are welcome. Here are our contributing guidelines.

phwebi avatar Oct 04 '21 19:10 phwebi