Skip to content

Commit

Permalink
fix(project): implement calculating 100vh correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
royschut committed Jun 23, 2021
1 parent f190c28 commit 2e09110
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/components/Layout/Layout.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
.layout {
display: flex;
flex-direction: column;
min-height: 100vh;
height: 100vh;
height: calc(var(--vh, 1vh) * 100);
}
.main {
flex: 1;
Expand Down
11 changes: 10 additions & 1 deletion src/components/Layout/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactNode, FC, useState, useContext } from 'react';
import React, { ReactNode, FC, useState, useContext, useEffect } from 'react';
import { Helmet } from 'react-helmet';
import { useTranslation } from 'react-i18next';

Expand Down Expand Up @@ -29,6 +29,15 @@ const Layout: FC<LayoutProps> = ({ children }) => {
const hasDynamicBlur = options.dynamicBlur === true;
const banner = assets.banner;

useEffect(() => {
const calculateViewHeight = () => document.documentElement.style.setProperty('--vh', `${window.innerHeight * 0.01}px`);

calculateViewHeight();
window.addEventListener('resize', () => calculateViewHeight);

return () => document.removeEventListener('resize', calculateViewHeight);
}, []);

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

0 comments on commit 2e09110

Please sign in to comment.