I am looking for a way to allow users to copy and paste a block of text without including inline controls, such as buttons.
In Chrome, adding user-select: none;
to the controls achieves this. When the user selects the entire paragraph, the buttons are not included in the selection, resulting in only the content getting copied.
However, in Safari, using -webkit-user-select: none;
, although the selection visually indicates that the buttons are not selected, their content is still included when copying and pasting.
For example, in the demo below, the desired outcome is to copy "13", not "123" when selecting everything:
button {
-webkit-user-select: none;
user-select: none;
}
1<button>2</button>3
Other attempted solutions include placing the content in a shadow DOM, which did not work as expected.
A potential solution could involve converting the text into an SVG or manipulating the DOM so that the buttons are visually inline but not present within the actual DOM structure.