Skip to content

Commit b16be00

Browse files
authored
adding copy button click event (github#26074)
1 parent 58286e0 commit b16be00

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

components/lib/events.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,15 @@ function initClipboardEvent() {
245245
})
246246
}
247247

248+
function initCopyButtonEvent() {
249+
document.documentElement.addEventListener('click', (evt) => {
250+
const target = evt.target as HTMLElement
251+
const button = target.closest('.js-btn-copy') as HTMLButtonElement
252+
if (!button) return
253+
sendEvent({ type: EventType.navigate, navigate_label: 'copy icon button' })
254+
})
255+
}
256+
248257
function initLinkEvent() {
249258
document.documentElement.addEventListener('click', (evt) => {
250259
const target = evt.target as HTMLElement
@@ -267,6 +276,7 @@ export default function initializeEvents() {
267276
initPageAndExitEvent() // must come first
268277
initLinkEvent()
269278
initClipboardEvent()
279+
initCopyButtonEvent()
270280
initPrintEvent()
271281
// survey event in ./survey.js
272282
// experiment event in ./experiment.js

components/rest/CodeBlock.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function CodeBlock({ verb, headingLang, codeBlock, highlight }: Props) {
3434
`${headingLang}`
3535
)}
3636
<Tooltip direction="w" aria-label={isCopied ? 'Copied!' : 'Copy to clipboard'}>
37-
<button className="btn-octicon" onClick={() => setCopied()}>
37+
<button className="js-btn-copy btn-octicon" onClick={() => setCopied()}>
3838
{isCopied ? <CheckIcon /> : <CopyIcon />}
3939
</button>
4040
</Tooltip>
@@ -57,7 +57,7 @@ export function CodeBlock({ verb, headingLang, codeBlock, highlight }: Props) {
5757
</code>
5858
{!headingLang && (
5959
<Tooltip direction="w" aria-label={isCopied ? 'Copied!' : 'Copy to clipboard'}>
60-
<button className="btn-octicon" onClick={() => setCopied()}>
60+
<button className="js-btn-copy btn-octicon" onClick={() => setCopied()}>
6161
{isCopied ? <CheckIcon /> : <CopyIcon />}
6262
</button>
6363
</Tooltip>

0 commit comments

Comments
 (0)