You need to pass event to function instead just ID. This way you can check for Ctrl:
function handleClick(event) {
const documentID = event.id;
if (event.ctrlKey) {
window.open(`/document/${documentID}`, "_blank")
} else {
navigate("/document/" + documentID)
}
}
<ListItem onClick={(event) => handleClick(event)}>
You can also extend your function for mouse wheel click:
function handleClick(event) {
event.preventDefault();
const documentID = event.id;
if (event.ctrlKey || event.button === 1) {
window.open(`/document/${documentID}`, "_blank")
} else if (event.type === 'click') {
navigate("/document/" + documentID)
}
}
<ListItem onClick={(event) => handleClick(event)} onMouseDown={(event) => handleClick(event)}>
Use anchor <a> (or react <Link> component) tag if you can, this is prefered way.
handleClickyou can use thereact-routerlibrary and create the link with the<Link/>component. In this way it works like a normal<a>link.