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
pull/6288/head
Neil 3 months ago committed by GitHub
parent a1037d1db2
commit d7ff5b9abc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      src/components/TopicDetail/TopicDetail.tsx
  2. 11
      src/lib/dom.ts
  3. 1
      tailwind.config.cjs

@ -30,6 +30,7 @@ import { GitHubIcon } from '../ReactIcons/GitHubIcon.tsx';
import { GoogleIcon } from '../ReactIcons/GoogleIcon.tsx';
import { YouTubeIcon } from '../ReactIcons/YouTubeIcon.tsx';
import { resourceTitleFromId } from '../../lib/roadmap.ts';
import { lockBodyScroll } from '../../lib/dom.ts';
type TopicDetailProps = {
resourceTitle?: string;
@ -262,6 +263,8 @@ export function TopicDetail(props: TopicDetailProps) {
useEffect(() => {
if (isActive) topicRef?.current?.focus();
lockBodyScroll(isActive);
}, [isActive]);
if (!isActive) {

@ -6,3 +6,14 @@ export function replaceChildren(parentNode: Element, newChild: Element) {
parentNode.innerHTML = '';
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: {
hoverOnlyWhenSupported: true,
},
safelist: ['overflow-hidden'],
theme: {
extend: {
typography: {

Loading…
Cancel
Save