mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-12 00:37:19 +00:00
Don't listen for two-up keyboard shortcuts if in input (#979)
This commit is contained in:
@@ -69,7 +69,7 @@ export default class TwoUp extends HTMLElement {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener('keydown', event => this._onKeyDown(event));
|
window.addEventListener('keydown', (event) => this._onKeyDown(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
connectedCallback() {
|
connectedCallback() {
|
||||||
@@ -98,19 +98,24 @@ export default class TwoUp extends HTMLElement {
|
|||||||
|
|
||||||
// KeyDown event handler
|
// KeyDown event handler
|
||||||
private _onKeyDown(event: KeyboardEvent) {
|
private _onKeyDown(event: KeyboardEvent) {
|
||||||
|
const target = event.target;
|
||||||
|
if (target instanceof HTMLElement && target.closest('input')) return;
|
||||||
|
|
||||||
if (event.code === 'Digit1' || event.code === 'Numpad1') {
|
if (event.code === 'Digit1' || event.code === 'Numpad1') {
|
||||||
this._position = 0;
|
this._position = 0;
|
||||||
this._relativePosition = 0;
|
this._relativePosition = 0;
|
||||||
this._setPosition();
|
this._setPosition();
|
||||||
} else if (event.code === 'Digit2' || event.code === 'Numpad2') {
|
} else if (event.code === 'Digit2' || event.code === 'Numpad2') {
|
||||||
const dimensionAxis = this.orientation === 'vertical' ? 'height' : 'width';
|
const dimensionAxis =
|
||||||
|
this.orientation === 'vertical' ? 'height' : 'width';
|
||||||
const bounds = this.getBoundingClientRect();
|
const bounds = this.getBoundingClientRect();
|
||||||
|
|
||||||
this._position = bounds[dimensionAxis] / 2;
|
this._position = bounds[dimensionAxis] / 2;
|
||||||
this._relativePosition = (this._position / bounds[dimensionAxis]) / 2;
|
this._relativePosition = this._position / bounds[dimensionAxis] / 2;
|
||||||
this._setPosition();
|
this._setPosition();
|
||||||
} else if (event.code === 'Digit3' || event.code === 'Numpad3') {
|
} else if (event.code === 'Digit3' || event.code === 'Numpad3') {
|
||||||
const dimensionAxis = this.orientation === 'vertical' ? 'height' : 'width';
|
const dimensionAxis =
|
||||||
|
this.orientation === 'vertical' ? 'height' : 'width';
|
||||||
const bounds = this.getBoundingClientRect();
|
const bounds = this.getBoundingClientRect();
|
||||||
|
|
||||||
this._position = bounds[dimensionAxis];
|
this._position = bounds[dimensionAxis];
|
||||||
|
|||||||
Reference in New Issue
Block a user