From d02a18bfff5d588ac2409abe28cf9de622845f97 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 29 May 2020 01:44:09 +0100 Subject: [PATCH] Apply FocusLock to ImageView to capture Escape handling Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/views/elements/ImageView.js | 24 +++++++++------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/components/views/elements/ImageView.js b/src/components/views/elements/ImageView.js index edadc841a3..e39075cedc 100644 --- a/src/components/views/elements/ImageView.js +++ b/src/components/views/elements/ImageView.js @@ -15,8 +15,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -'use strict'; - import React from 'react'; import PropTypes from 'prop-types'; import {MatrixClientPeg} from "../../../MatrixClientPeg"; @@ -27,6 +25,7 @@ import AccessibleButton from "./AccessibleButton"; import Modal from "../../../Modal"; import * as sdk from "../../../index"; import {Key} from "../../../Keyboard"; +import FocusLock from "react-focus-lock"; export default class ImageView extends React.Component { static propTypes = { @@ -50,16 +49,6 @@ export default class ImageView extends React.Component { this.state = { rotationDegrees: 0 }; } - // XXX: keyboard shortcuts for managing dialogs should be done by the modal - // dialog base class somehow, surely... - componentDidMount() { - document.addEventListener("keydown", this.onKeyDown); - } - - componentWillUnmount() { - document.removeEventListener("keydown", this.onKeyDown); - } - onKeyDown = (ev) => { if (ev.key === Key.ESCAPE) { ev.stopPropagation(); @@ -195,7 +184,14 @@ export default class ImageView extends React.Component { const effectiveStyle = {transform: `rotate(${rotationDegrees}deg)`, ...style}; return ( -