mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-08-12 20:24:21 +02:00
Ensure when TopicDetail is open document.body stops scrolling (#6285)
* fix: ensure TopicDetail locks the body when open * chore: ensure 'overflow-hidden' is always available via safelist * revert: prettier changes
This commit is contained in:
@@ -30,6 +30,7 @@ import { GitHubIcon } from '../ReactIcons/GitHubIcon.tsx';
|
|||||||
import { GoogleIcon } from '../ReactIcons/GoogleIcon.tsx';
|
import { GoogleIcon } from '../ReactIcons/GoogleIcon.tsx';
|
||||||
import { YouTubeIcon } from '../ReactIcons/YouTubeIcon.tsx';
|
import { YouTubeIcon } from '../ReactIcons/YouTubeIcon.tsx';
|
||||||
import { resourceTitleFromId } from '../../lib/roadmap.ts';
|
import { resourceTitleFromId } from '../../lib/roadmap.ts';
|
||||||
|
import { lockBodyScroll } from '../../lib/dom.ts';
|
||||||
|
|
||||||
type TopicDetailProps = {
|
type TopicDetailProps = {
|
||||||
resourceTitle?: string;
|
resourceTitle?: string;
|
||||||
@@ -262,6 +263,8 @@ export function TopicDetail(props: TopicDetailProps) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isActive) topicRef?.current?.focus();
|
if (isActive) topicRef?.current?.focus();
|
||||||
|
|
||||||
|
lockBodyScroll(isActive);
|
||||||
}, [isActive]);
|
}, [isActive]);
|
||||||
|
|
||||||
if (!isActive) {
|
if (!isActive) {
|
||||||
|
@@ -6,3 +6,14 @@ export function replaceChildren(parentNode: Element, newChild: Element) {
|
|||||||
parentNode.innerHTML = '';
|
parentNode.innerHTML = '';
|
||||||
parentNode.append(newChild);
|
parentNode.append(newChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function lockBodyScroll(shouldLock: boolean) {
|
||||||
|
const isClient = document && 'body' in document;
|
||||||
|
if (!isClient) return;
|
||||||
|
|
||||||
|
if (shouldLock) {
|
||||||
|
document.body.classList.add('overflow-hidden');
|
||||||
|
} else {
|
||||||
|
document.body.classList.remove('overflow-hidden');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -7,6 +7,7 @@ module.exports = {
|
|||||||
future: {
|
future: {
|
||||||
hoverOnlyWhenSupported: true,
|
hoverOnlyWhenSupported: true,
|
||||||
},
|
},
|
||||||
|
safelist: ['overflow-hidden'],
|
||||||
theme: {
|
theme: {
|
||||||
extend: {
|
extend: {
|
||||||
typography: {
|
typography: {
|
||||||
|
Reference in New Issue
Block a user