Added keyboard shortcuts for zoom (#5334)

GitOrigin-RevId: b284f923e9b4aba7837430239b09e05bb0308d09
This commit is contained in:
Miguel Serrano 2021-10-08 11:25:43 +02:00 committed by Copybot
parent a4799c29b6
commit 07ca18cdbb

View file

@ -228,10 +228,35 @@ function PdfJsViewer({ url }) {
}
}, [pdfJsWrapper])
const handleKeyDown = useCallback(
event => {
if (!initialised) {
return
}
if ((event.metaKey || event.ctrlKey) && event.key === '=') {
event.preventDefault()
setZoom('zoom-in')
} else if ((event.metaKey || event.ctrlKey) && event.key === '-') {
event.preventDefault()
setZoom('zoom-out')
} else if ((event.metaKey || event.ctrlKey) && event.key === '0') {
event.preventDefault()
setZoom('fit-width')
}
},
[initialised, setZoom]
)
/* eslint-disable jsx-a11y/no-noninteractive-tabindex */
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
return (
<div className="pdfjs-viewer" ref={handleContainer}>
<div className="pdfjs-viewer-inner" tabIndex="0">
<div
className="pdfjs-viewer-inner"
role="tabpanel"
tabIndex="0"
onKeyDown={handleKeyDown}
>
<div className="pdfViewer" />
</div>
<div className="pdfjs-controls">