react-hotkeys icon indicating copy to clipboard operation
react-hotkeys copied to clipboard

[BUG] GlobalHotKeys disrupts layout, but HotKeys does not

Open Nantris opened this issue 6 years ago • 4 comments

Describe the bug

Seems like some sort of flex issue. It changes flex orientation in some cases.

Expected behavior Changing components (Global vs non-global) should not alter layout Platform (please complete the following information):

  • Version of react-hotkeys 2.x
  • Browser [e.g. chrome, safari]
  • OS: [e.g. iOS]

Are you willing and able to create a PR request to fix this issue? No

Nantris avatar Oct 08 '19 01:10 Nantris

Can you verify the version you are using? The latest version doesn't need a container I believe.

How is <GlobalHotKeys /> being used in your app?

// Unnecessarily nested

<App>
  <MainContentTheme>
    <GlobalHotkeys children={restOfApp} />
  </MainContentTheme>
</App>


// or 
<App>
  <GlobalHotkeys />
  <MainContentTheme>
    {restOfApp}
  </MainContentTheme>
</App>

// You can also try moving it higher in the tree
<>
  <App>  
    <MainContentTheme children={restOfApp} />
  </App>
  <GlobalHotkeys />
</>

sbrichardson avatar Oct 12 '19 15:10 sbrichardson

It was at the highest level. It was necessary for me to nest it inside of another layout componen, which was not necessary with <HotKeys />

Nantris avatar Oct 12 '19 19:10 Nantris

Hi @Slapbox,

Are you rendering <GlobalHotKeys> with children, or without? Rendering without children actually doesn't mount anything to the DOM (but still renders <GlobalHotKeys/> in the React component tree).

Please let me know exactly how you're using it, so I can assist you.

Thank you, @sbrichardson for trying to help out. I really appreciate the support.

greena13 avatar Oct 20 '19 12:10 greena13

Hey @greena13, thanks for your response. That makes sense about rendering without children, but we are rendering with children. We were able to work around it by wrapping it like so:

<div style={{ display: 'flex' }}>
  <GlobalHotKeys>{children}</GlobalHotKeys>
</div>

I just thought it odd that a discrepancy in layout would exist.

Nantris avatar Oct 20 '19 18:10 Nantris