Skip to content

"Copy to Clipboard" icon does not work inside a bootstrap modal container #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MrLeebo opened this issue Oct 30, 2017 · 10 comments
Closed

Comments

@MrLeebo
Copy link
Contributor

MrLeebo commented Oct 30, 2017

I built a repro using https://esnextb.in/ but it seems that the site's Save function is currently broken.

Repro: https://gist.github.com/MrLeebo/84a3059a7a33993c34567172ec77698f

  1. Go to https://esnextb.in/
  2. Copy the "code.js" file into the Code tab
  3. Copy the "index.html" file into the HTML tab
  4. Package tab should auto-populate but you can check it with the "package.json" file
  5. Click the "Copy to clipboard" icon. Clipboard does not change
  6. If you remove the Modal and simply render the JsonView like normal, the icon works correctly and the clipboard contains the JSON contents
@mac-s-g
Copy link
Owner

mac-s-g commented Oct 30, 2017

thanks for reporting the issue!

I'll try to replicate as soon as I have a chance.

@mac-s-g
Copy link
Owner

mac-s-g commented Dec 11, 2017

@MrLeebo would you mind testing with [email protected]? the clipboard code changed a bit and i'm wondering if it impacted this issue.

@MrLeebo
Copy link
Contributor Author

MrLeebo commented Dec 11, 2017

@mac-s-g Thanks, but it doesn't seem to have made a difference.

@stephenshank
Copy link

@mac-s-g Thanks for such an awesome project! I am experiencing the same issue. Happy to help if possible.

@mac-s-g mac-s-g changed the title "Copy to Clipboard" icon does not work inside a modal container "Copy to Clipboard" icon does not work inside a bootstrap modal container Dec 27, 2017
@mac-s-g
Copy link
Owner

mac-s-g commented Dec 27, 2017

updating title because I was able to use copy-to-clipboard when using a semantic-ui modal rather than bootstrap. I'll dig in to bootstrap a bit.

@mac-s-g
Copy link
Owner

mac-s-g commented Dec 27, 2017

also verified that the issue does occur when using a react-bootstrap modal at version 0.31.5

@mac-s-g
Copy link
Owner

mac-s-g commented Dec 27, 2017

relevant threads:

  1. https://stackoverflow.com/questions/38398070/bootstrap-modal-does-not-work-with-clipboard-js-on-firefox
  2. https://stackoverflow.com/questions/46107274/copy-text-to-clipboard-not-working-in-bootstrap-modal-dialog

here is the only solution I can find:
zenorocha/clipboard.js#155 (comment)

I hope that helps. I'm closing this issue because I don't think the problem is caused by RJV source. It's a documented issue with bootstrap modals.

@mac-s-g mac-s-g closed this as completed Dec 27, 2017
stephenshank added a commit to stephenshank/hyphy-vision that referenced this issue Feb 1, 2018
It is well known that there are issues with copying to the
clipboard inside of a Bootstrap modal:

mac-s-g/react-json-view#131

After briefly trying some of the suggestions in the above
link with no success, I decided to temporarily disable this
desirable feature until we can find something that works.
@vaclav-purchart
Copy link

vaclav-purchart commented Dec 4, 2018

I've found similar issue when using json-react-view using @material-ui. However there is a simple workaround (at least for Chrome):

	handleCopy = (copy) => {
		navigator.clipboard.writeText(JSON.stringify(copy.src, null, '\t'))
	}

...

	<ReactJsonView enableClipboard={this.handleCopy}>

@KilianB
Copy link

KilianB commented Mar 26, 2024

I've found similar issue when using json-react-view using @material-ui. However there is a simple workaround (at least for Chrome):

	handleCopy = (copy) => {
		navigator.clipboard.writeText(JSON.stringify(copy.src, null, '\t'))
	}

...
	<ReactJsonView enableClipboard={this.handleCopy}>

Inside a Mui model adding disableEnforceFocus resolved the issue for me.

<Modal disableEnforceFocus>

raethlein added a commit to streamlit/streamlit that referenced this issue Jul 23, 2024
## Describe your changes

Closes #9112

Right now, copy buttons in dialogs don't work. This seems to be because
the Modal swallows the focus events. This PR fixes this by using the
`container` property from `ClipboardJS` (inspiration from
[here](mac-s-g/react-json-view#131 (comment))).
This is now also used in our `ReactJSON` element.

In the first iteration we set `focusLock={false}` on the Dialog which
also solved this issue. However, that came with an accessibility
drawback where you would be able to select elements outside of the
container via the `Tab` key.

## GitHub Issue Link (if applicable)

## Testing Plan

- Explanation of why no additional tests are needed
- Unit Tests (JS and/or Python)
- E2E Tests
  - Add an e2e test to ensure that copying works
- Any manual testing needed?

---

**Contribution License Agreement**

By submitting this pull request you agree that all contributions to this
project are made under the Apache 2.0 license.
@tjesposito
Copy link

tjesposito commented Aug 28, 2024

@vaclav-purchart suggestion worked for me! (same issue- copy not working within an MUI Dialog) 👍

benjamin-awd pushed a commit to benjamin-awd/streamlit that referenced this issue Sep 29, 2024
## Describe your changes

Closes streamlit#9112

Right now, copy buttons in dialogs don't work. This seems to be because
the Modal swallows the focus events. This PR fixes this by using the
`container` property from `ClipboardJS` (inspiration from
[here](mac-s-g/react-json-view#131 (comment))).
This is now also used in our `ReactJSON` element.

In the first iteration we set `focusLock={false}` on the Dialog which
also solved this issue. However, that came with an accessibility
drawback where you would be able to select elements outside of the
container via the `Tab` key.

## GitHub Issue Link (if applicable)

## Testing Plan

- Explanation of why no additional tests are needed
- Unit Tests (JS and/or Python)
- E2E Tests
  - Add an e2e test to ensure that copying works
- Any manual testing needed?

---

**Contribution License Agreement**

By submitting this pull request you agree that all contributions to this
project are made under the Apache 2.0 license.
edegp pushed a commit to edegp/streamlit that referenced this issue Jan 19, 2025
## Describe your changes

Closes streamlit#9112

Right now, copy buttons in dialogs don't work. This seems to be because
the Modal swallows the focus events. This PR fixes this by using the
`container` property from `ClipboardJS` (inspiration from
[here](mac-s-g/react-json-view#131 (comment))).
This is now also used in our `ReactJSON` element.

In the first iteration we set `focusLock={false}` on the Dialog which
also solved this issue. However, that came with an accessibility
drawback where you would be able to select elements outside of the
container via the `Tab` key.

## GitHub Issue Link (if applicable)

## Testing Plan

- Explanation of why no additional tests are needed
- Unit Tests (JS and/or Python)
- E2E Tests
  - Add an e2e test to ensure that copying works
- Any manual testing needed?

---

**Contribution License Agreement**

By submitting this pull request you agree that all contributions to this
project are made under the Apache 2.0 license.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants