Skip to content

Commit

Permalink
fix handling of codeBlock copy value
Browse files Browse the repository at this point in the history
  • Loading branch information
thatmattlove committed Feb 8, 2021
1 parent 3d33aee commit 60d8c2c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion components/codeBlock/codeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ export const CodeBlock: React.FC<ICodeBlock> = (props: ICodeBlock) => {
colorScheme: ctx.copyButton.colorScheme,
variant: 'ghost',
});
const { hasCopied, onCopy } = useClipboard(children);

let copyValue = '';
if (typeof children === 'string') {
copyValue = children;
} else {
copyValue = children.props.children;
}

const { hasCopied, onCopy } = useClipboard(copyValue);

return (
<Box
Expand Down
2 changes: 1 addition & 1 deletion components/codeBlock/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { BoxProps } from '@chakra-ui/react';

export interface ICodeBlock extends BoxProps {
children: string;
children: string | JSX.Element;
}

0 comments on commit 60d8c2c

Please sign in to comment.