WIP: Esc key on lightbox

This commit is contained in:
Bruno Windels 2020-10-30 19:59:42 +01:00
parent 597a57eae3
commit c847cfb200

View file

@ -42,12 +42,22 @@ export class LightboxView extends TemplateView {
const details = t.div({ const details = t.div({
className: "details" className: "details"
}, [t.strong(vm => vm.name), t.br(), "uploaded by ", t.strong(vm => vm.sender), vm => ` at ${vm.time} on ${vm.date}.`]); }, [t.strong(vm => vm.name), t.br(), "uploaded by ", t.strong(vm => vm.sender), vm => ` at ${vm.time} on ${vm.date}.`]);
return t.div({className: "lightbox", onClick: evt => this.close(evt)}, [image, loading, details, close]); return t.div({
className: "lightbox",
onClick: evt => this.clickToClose(evt),
onKeydown: evt => this.closeOnEscKey(evt)
}, [image, loading, details, close]);
} }
close(evt) { clickToClose(evt) {
if (evt.target === this.root()) { if (evt.target === this.root()) {
this.value.close(); this.value.close();
} }
} }
closeOnEscKey(evt) {
if (evt.key === "Escape") {
this.value.close();
}
}
} }