useHotKeys inside Iframe
See original GitHub issueHi there!
version: react-hotkeys-hook@4.0.2
I’m trying to use useHotKeys
inside react-frame-component
Iframe, but when i’m focusing on iframe and pressing some hotkeys, events doesn’t work, nothing happens, example:
import React, { memo, useRef, useEffect, useCallback } from 'react'
import Frame, { FrameContextConsumer, useFrame } from 'react-frame-component'
import {useHotkeys} from 'react-hotkeys-hook'
const InnerComponent = () => {
const { document, window } = useFrame();
useHotkeys('s', (event) => {
console.log('s pressed');
})
return null;
};
const Editor = () => {
return (
<>
<Frame>
<InnerComponent/>
</Frame>
</>
)
}
export default memo(Editor)
what i’m doing wrong, or maybe i need to pass some arguments to useHotkeys
function?
thanks!
Issue Analytics
- State:
- Created 10 months ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
useHotkeys from within an iframe · Issue #4731 - GitHub
I am trying to get hotkeys working with a BlueprintJS app residing within an iframe (via react-frame-component ). In the code sandbox above,...
Read more >Using jQuery hotkeys from within a blurred iFrame
I'm using jQuery Hotkeys within an iframe (iFrame A), on a page with two iFrames (A and B). When the focus is on...
Read more >Can't use hotkeys defined for page in UI for ASP.NET AJAX
Hello, The content area of RadEditor is by default rendered as an iframe element (ContentAreaMode="iframe"), which is another document which ...
Read more >Iframes - Minimal Documentation
Use Hotkeys to adjust iframes globally: Cycle between iframe width options. Helper classes.
Read more >How to execute the keyboard shortcuts when Focus is ... - MSDN
If iFrame is having the focus then i am not able generate the Keyboard shortcut alerts. May i know how to implement? I...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Had similar issues with other libs when using React Portals (like react-helmet and many css-in-js libs that want to access
<head>
and all assume that<head>
is located atdocument.getElementsByTagName('head')[0]
).It boils down to listening on the wrong
document
(i.e. the parent document, where react lives, instead of listening on the iframe’sdocument
). It’s likely that being able to passdocument
to the hook will resolve the issueStarting with 4.3.0 you can set a different document to bind to in the useHotkey hook like so:
Thanks to @mbrevda for the pointer to the solution!