dimanche 4 juillet 2021

Simulate "shift" pressing key on checkbox to select multiple rows

I have the following input

 <input type="checkbox"  checked={isChecked}

onChange={handleOnChange}/>

and my function is this

 const handleOnChange = () => {
  let element:any = document.querySelector('input');
 element.onkeydown = (e: { key: any; })  => alert(e.key);
element.dispatchEvent(new KeyboardEvent('keydown',{'key':'Shift'}));
  setIsChecked(!isChecked);


 
};

This checkbox is created dinamically as I add new rows and I would like to simulate holding the key "shift" so that when I check multiple checkboxes these rows remain selected.

I am using reactjs.




Aucun commentaire:

Enregistrer un commentaire