Skip to content

Commit

Permalink
fix: preserve initial body overflow value (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
nuragic committed Jan 7, 2022
1 parent 57b055f commit f6b5f41
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/components/Toolbar/index.tsx
@@ -1,4 +1,4 @@
import React, { Fragment, useContext, useEffect } from 'react';
import React, { Fragment, useContext, useEffect, useRef } from 'react';
import { IProps } from '../../Editor';
import { EditorContext, PreviewType, ContextStore } from '../../Context';
import { ICommand } from '../../commands';
Expand All @@ -15,6 +15,8 @@ export interface IToolbarProps extends IProps {
export function ToolbarItems(props: IToolbarProps) {
const { prefixCls } = props;
const { fullscreen, preview, barPopup = {}, commandOrchestrator, dispatch } = useContext(EditorContext);
const originalOverflow = useRef('');

function handleClick(command: ICommand<string>, name?: string) {
if (!dispatch) return;
const state: ContextStore = { barPopup: { ...barPopup } };
Expand Down Expand Up @@ -46,9 +48,19 @@ export function ToolbarItems(props: IToolbarProps) {

useEffect(() => {
if (document) {
document.body.style.overflow = !fullscreen ? '' : 'hidden';
if (fullscreen) {
// prevent scroll on fullscreen
document.body.style.overflow = 'hidden';
} else {
// get the original overflow only the first time
if (!originalOverflow.current) {
originalOverflow.current = window.getComputedStyle(document.body, null).overflow;
}
// reset to the original overflow
document.body.style.overflow = originalOverflow.current;
}
}
}, [fullscreen]);
}, [fullscreen, originalOverflow]);

return (
<ul>
Expand Down

1 comment on commit f6b5f41

@vercel
Copy link

@vercel vercel bot commented on f6b5f41 Jan 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.