theKashey / react-focus-lock

It is a trap! A lock for a Focus. 🔓
MIT License
1.27k stars 67 forks source link

Focus-lock does not work with copy-to-clipboard libraries #213

Closed just-boris closed 2 years ago

just-boris commented 2 years ago

When FocusLock is activated on the page, the underlying elements cannot do copy-to-clipboard operation with an invisible textarea, because focus lock does not allow to select the content there

Live demo: https://codesandbox.io/s/distracted-dubinsky-0tfsrh?file=/src/App.tsx

import copyToClipboard from "copy-text-to-clipboard";
import FocusLock from "react-focus-lock";

<FocusLock>
  <button onClick={() => copyToClipboard("2")}>Click me!</button>
</FocusLock>

P.S. I am aware about navigator.clipboard.writeText API, but not all browsers support it, so here comes this issue

theKashey commented 2 years ago

Interesting task. There are a few ways to solve it, and I could not pick one. Let me just list all opportunities.

I cannot see a good way to solve this problem from the focus-lock side. It should do what it does.

just-boris commented 2 years ago

Thanks! Suggested workarounds make sense for me, no actions required