Skip to content

Commit

Permalink
[Draft] Try to prevent the link anchor when selecting
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfauquette committed Apr 21, 2024
1 parent 6577056 commit b40c3fe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
30 changes: 30 additions & 0 deletions docs/src/modules/components/GoogleAnalytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ import { useNoSsrCodeStyling } from 'docs/src/modules/utils/codeStylingSolution'
import { useUserLanguage } from '@mui/docs/i18n';
import { pathnameToLanguage } from 'docs/src/modules/utils/helpers';

function handleClick2(event) {
const isRangeSelection = document.getSelection().type === 'Range';

if (isRangeSelection) {
console.log('prevent');
event.preventDefault();
return;
}
console.log("don't prevent");
return;
}

// So we can write code like:
//
// <Button
Expand Down Expand Up @@ -54,6 +66,24 @@ function GoogleAnalytics() {
document.addEventListener('click', handleClick);
}
}, []);

React.useEffect(() => {
const elements = document.getElementsByClassName('title-link-to-anchor');

for (var i = 0; i < elements.length; i++) {
elements[i].addEventListener('click', handleClick2, false);
}

// document.addEventListener('click', handleClick2);

return () => {
for (var i = 0; i < elements.length; i++) {
elements[i].removeEventListener('click', handleClick2);
}
// document.removeEventListener('click', handleClick2);
};
}, []);

const router = useRouter();
const timeout = React.useRef();

Expand Down
2 changes: 2 additions & 0 deletions packages/mui-docs/src/MarkdownElement/MarkdownElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ const Root = styled('div')(
position: 'relative',
display: 'flex',
alignItems: 'center',
userSelect: 'text',
'-webkit-user-drag': 'none',
},
'& .anchor-icon': {
// To prevent the link to get the focus.
Expand Down

0 comments on commit b40c3fe

Please sign in to comment.