Skip to content

Commit

Permalink
Merge pull request #660 from h3poteto/iss-470/image
Browse files Browse the repository at this point in the history
refs #470 Add shortcut to show next/previous image
  • Loading branch information
h3poteto authored Apr 19, 2023
2 parents d6e1398 + 37e1c22 commit e2bb694
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/components/Media.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,27 @@ const Media: React.FC<Props> = props => {
setIndex(current => current - 1)
}, [props.media, index, setIndex])

const handleKeyPress = useCallback(
(event: KeyboardEvent) => {
if (props.opened) {
if (event.key === 'ArrowLeft') {
previous()
} else if (event.key === 'ArrowRight') {
next()
}
}
},
[props.opened, previous, next]
)

useEffect(() => {
document.addEventListener('keydown', handleKeyPress)

return () => {
document.removeEventListener('keydown', handleKeyPress)
}
}, [handleKeyPress])

return (
<Modal
open={props.opened}
Expand Down

0 comments on commit e2bb694

Please sign in to comment.