Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
calc playground scrollbar postion on resize
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed Nov 6, 2019
1 parent 1151f36 commit cdc117e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions @antv/gatsby-theme-antv/site/components/PlayGrounds.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useRef, useEffect } from 'react';
import React, { useState, useRef, useEffect, useCallback } from 'react';
import classNames from 'classnames';
import { Tooltip } from 'antd';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -50,14 +50,25 @@ const PlayGrounds: React.FC<PlayGroundsProps> = ({
calcScrollPostion(e.target);
};

useEffect(() => {
const onResize = useCallback(() => {
if (playgroundScrollDiv && playgroundScrollDiv.current) {
const div = playgroundScrollDiv!.current!;
updateHasHorizontalScrollbar(div.scrollWidth > div.clientWidth);
calcScrollPostion(div);
}
}, [playgroundScrollDiv]);

useEffect(() => {
onResize();
}, [examples]);

useEffect(() => {
window.addEventListener('resize', onResize);
return () => {
window.removeEventListener('resize', onResize);
};
}, []);

return (
<div className={styles.container}>
<div
Expand Down

0 comments on commit cdc117e

Please sign in to comment.