Problem/Motivation
The copy button is sometimes failing to copy data to the clipboard. When that happens, the underlying copy to clipboard functionality fails everywhere it is used: on theme suggestion file names, and on the file path input element as well.
Steps to reproduce
Install the module; click an element on the page; Activate the Selected tab; click on one of the theme suggestion inputs. It might happen that the data won't be copied to the clipboard as expected.
Proposed resolution
This is an intermittent problem, sometimes being triggered, sometimes, not.
It happens on this piece of code when the clipboard API is found to be activated on the browser.
clipboardCopy(contentRefField) {
const textToCopy = contentRefField.textContent;
if (navigator.clipboard) {
navigator.clipboard.writeText(textToCopy);
} else {
contentRefField.select();
document.execCommand("copy");
contentRefField.focus();
}
},
The problem is associated with the fact that this line (const textToCopy = contentRefField.textContent) is not properly pulling the value within the input field. The correct approach for pulling the value of an input field would look like this (const textToCopy = contentRefField.value). When trying to write the content to the clipboard using the Clipboard API (navigator.clipboard.writeText(textToCopy)), it fails due to the fact that variable textToCopy is empty.
Remaining tasks
Fix the problem described.
User interface changes
The fix won't affect any UI elements.
API changes
--
Data model changes
--
Issue fork visual_debugger-3478613
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mabho commentedComment #4
mabho commentedComment #5
mabho commentedComment #6
mabho commentedComment #8
mabho commented