I am creating a multi-date-picker custom element that allows a user to pick a series of dates. The idea is if the user simply clicks a date, that starts the date selection over and all previously selected dates are cleared from the selection array. If the user holds CTRL and clicks a date, that date is added to the array of selected dates.
The problem I’m having is trying to figure out how to know if the CTRL key is being held down when the user clicks on a date. There is no input
element involved with my custom element so it doesn’t appear that keydown.trigger
is available to me.
I tried the following:
export class DatePickerCustomElement {
constructor(){
this.keyPressCallback = this.keyPress.bind(this);
...
}
keyPress(e){
console.log(e);
}
attached(){
window.addEventListener('keypress', this.keyPressCallback, false)
}
detached(){
window.removeEventListener('keypress', this.keyPressCallback)
}
}
However, this never seems to work. Any ideas?