I am currently working on a multi item selection component in Vue.js 3.
Each item is represented by a <div> element containing a checkbox.
For a feature I want to implement I need to detect when the Shift key is pressed while the mouse is over a <div>. (My goal is to have all the items between the item checked last and the item currently under the mouse highlighted while the Shift key is pressed, and then have them all checked with Shift + Click - but that is beside the point).
I tried to achieve this using @mouseover.shift like so:
<div v-for="item in items"
class="item"
@mouseover.shift="onMouseOverShift(item)"
>
Unfortunately, while @mouseover.shift works fine to detect whether Shift is pressed when the mouse enters the <div>, but does not trigger when the key is pressed while the mouse is already inside of the <div>.
Do you know what would be the best way to achieve what i am looking for?
I think you can use like this:
Then on the method onMouseOverShift you check if isMouseOver