Skip to content

Commit

Permalink
revert codecopy
Browse files Browse the repository at this point in the history
  • Loading branch information
sai6855 committed Jul 8, 2024
1 parent a7a1d2f commit f7d936d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/mui-docs/src/CodeCopy/CodeCopy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as React from 'react';
import { useRouter } from 'next/router';
import clipboardCopy from 'clipboard-copy';

const CodeBlockContext = React.createContext<React.MutableRefObject<HTMLDivElement | undefined>>({
current: undefined,
const CodeBlockContext = React.createContext<React.MutableRefObject<HTMLDivElement | null>>({
current: null,
});

/**
Expand All @@ -24,15 +24,15 @@ export function useCodeCopy(): React.HTMLAttributes<HTMLDivElement> {
onMouseLeave: (event) => {
if (rootNode.current === event.currentTarget) {
(rootNode.current.querySelector('.MuiCode-copy') as null | HTMLButtonElement)?.blur();
rootNode.current = undefined;
rootNode.current = null;
}
},
onFocus: (event) => {
rootNode.current = event.currentTarget;
},
onBlur: (event) => {
if (rootNode.current === event.currentTarget) {
rootNode.current = undefined;
rootNode.current = null;
}
},
};
Expand Down Expand Up @@ -66,7 +66,7 @@ function InitCodeCopy() {
const handleMouseLeave = () => {
if (rootNode.current === elm) {
(rootNode.current.querySelector('.MuiCode-copy') as null | HTMLButtonElement)?.blur();
rootNode.current = undefined;
rootNode.current = null;
}
};
elm.addEventListener('mouseleave', handleMouseLeave);
Expand All @@ -82,7 +82,7 @@ function InitCodeCopy() {
const handleFocusout = () => {
// use `focusout` because it bubbles from the copy button
if (rootNode.current === elm) {
rootNode.current = undefined;
rootNode.current = null;
}
};
elm.addEventListener('focusout', handleFocusout);
Expand Down Expand Up @@ -157,7 +157,7 @@ interface CodeCopyProviderProps {
* Any code block inside the tree can set the rootNode when mouse enter to leverage keyboard copy.
*/
export function CodeCopyProvider({ children }: CodeCopyProviderProps) {
const rootNode = React.useRef<HTMLDivElement | undefined>(undefined);
const rootNode = React.useRef<HTMLDivElement | null>(null);
React.useEffect(() => {
document.addEventListener('keydown', (event) => {
if (!rootNode.current) {
Expand Down

0 comments on commit f7d936d

Please sign in to comment.