Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit 863b373

Browse files
authored
fix: copy to clipboard did not always work (#1298)
Closes #1297. ### Summary of Changes Use the browser API for the clipboard directly instead of the `useClipboard` hook.
1 parent c3dd1fd commit 863b373

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

api-editor/gui/src/features/annotations/DataCopyButtons.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Button, ButtonGroup, Tooltip, useClipboard } from '@chakra-ui/react';
1+
import { Button, ButtonGroup, Tooltip } from '@chakra-ui/react';
22
import React from 'react';
33
import { FaClipboard } from 'react-icons/fa';
44
import { useAppSelector } from '../../app/hooks';
@@ -16,13 +16,23 @@ export const DataCopyButtons: React.FC<MinimalDataButtonsProps> = function ({ ta
1616
const pythonPackage = useAppSelector(selectRawPythonPackage);
1717
const declaration = pythonPackage.getDeclarationById(target);
1818
const usages = useAppSelector(selectUsages);
19-
const { onCopy: onCopyAPI } = useClipboard(
20-
details(jsonCode(buildMinimalAPIJson(declaration)), `Minimal API Data for \`${target}\``),
21-
);
22-
const { onCopy: onCopyUsages } = useClipboard(
23-
details(jsonCode(buildMinimalUsagesStoreJson(usages, declaration)), `Minimal Usage Store for \`${target}\``),
24-
);
25-
const { onCopy: onCopyQualifiedName } = useClipboard(declaration?.preferredQualifiedName() ?? '');
19+
20+
const onCopyAPI = () => {
21+
navigator.clipboard.writeText(
22+
details(jsonCode(buildMinimalAPIJson(declaration)), `Minimal API Data for \`${target}\``),
23+
);
24+
};
25+
const onCopyUsages = () => {
26+
navigator.clipboard.writeText(
27+
details(
28+
jsonCode(buildMinimalUsagesStoreJson(usages, declaration)),
29+
`Minimal Usage Store for \`${target}\``,
30+
),
31+
);
32+
};
33+
const onCopyQualifiedName = () => {
34+
navigator.clipboard.writeText(declaration?.preferredQualifiedName() ?? '');
35+
};
2636

2737
return (
2838
<ButtonGroup size="sm" variant="outline" isAttached>

0 commit comments

Comments
 (0)