I have a material-ui component Grid and I have a onKeyUp event on that
But somehow onKeyUp is not triggering
<Grid item xs={12} onKeyUp={handleClickOnKeyUp} sx={{cursor: "pointer"}} onClick=
{handleClickGrid}>
</Grid>
and the functions are
const handleClickOnKeyUp = () => {
console.log("123123123");
}
const handleClickGrid = () => {
console.log("456456456");
}
Other code for Grid and Grid items under Grid container is working fine, There is no problem in that
The onClick event is also working but onKeyUp is not working
What is the issue ?
You need to add a
tabIndexto the component (element) to allow it to accept focus. For example:Updated answer to additional comment:
If you'd also like to remove the focus outline, you can add the styling:
Working CodeSandbox: https://codesandbox.io/s/pensive-leaf-x4e6xv?file=/demo.js
Note: If you are concerned about accessibility, I'd be careful setting that
tabIndexproperty to anything other than zero (0).