Page MenuHomePhabricator

Copy button in Codex demos copies extra newline in Chrome
Closed, ResolvedPublic

Description

When I go to https://doc.wikimedia.org/codex/main/design-tokens/color.html using Chrome on Ubuntu, and I click the "Copy" button next to e.g. color-base--hover, the string that is copied to my clipboard has a newline at the start (i.e."\ncolor-base--hover").

This doesn't happen in Firefox. It seems like it might be caused by the complex code that tries to make this work in older iOS versions; the code mentions not being able to use textarea.select(); for that reason, but if I use that instead of range.selectNodeContents( textarea ); the bug goes away.

Event Timeline

Our use of document.execCommand( 'copy' ) might need to be reconsidered, since it is marked as deprecated, https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand

Perhaps instead we should use the Clipboard api? https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API

STH added a project: good first task.
STH moved this task from Inbox to Backlog on the Design-System-Team board.

Change 822479 had a related patch set uploaded (by Abijeet Patro; author: Abijeet Patro):

[design/codex@main] CopyTextButton: Use Clipboard API when available to copy code

https://gerrit.wikimedia.org/r/822479

Catrope assigned this task to abi_.

Change 822479 merged by jenkins-bot:

[design/codex@main] CopyTextButton: Use Clipboard API when available to copy code

https://gerrit.wikimedia.org/r/822479

Change 823725 had a related patch set uploaded (by Anne Tomasevich; author: Anne Tomasevich):

[mediawiki/core@master] Update Codex from v0.1.0-alpha.9 to v0.1.0-alpha.10

https://gerrit.wikimedia.org/r/823725

Change 823725 merged by jenkins-bot:

[mediawiki/core@master] Update Codex from v0.1.0-alpha.9 to v0.1.0-alpha.10

https://gerrit.wikimedia.org/r/823725