Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Header and ToggleSwitch Components to Close Navbar on Theme Toggle #739

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/ToggleSwitch/ToggleSwitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import emoji from "react-easy-emoji";
import StyleContext from "../../contexts/StyleContext";
import "./ToggleSwitch.scss";

const ToggleSwitch = () => {
const ToggleSwitch = ({handleMenuItemClick}) => {
const {isDark} = useContext(StyleContext);
const [isChecked, setChecked] = useState(isDark);
const styleContext = useContext(StyleContext);
Expand All @@ -16,6 +16,7 @@ const ToggleSwitch = () => {
onChange={() => {
styleContext.changeTheme();
setChecked(!isChecked);
handleMenuItemClick();
}}
/>
<span className="slider round">
Expand Down
19 changes: 16 additions & 3 deletions src/components/header/Header.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useContext} from "react";
import React, {useContext, useRef} from "react";
import Headroom from "react-headroom";
import "./Header.scss";
import ToggleSwitch from "../ToggleSwitch/ToggleSwitch";
Expand All @@ -24,6 +24,14 @@ function Header() {
const viewTalks = talkSection.display;
const viewResume = resumeSection.display;

const menuCheckboxRef = useRef(null);

const handleMenuItemClick = () => {
if (menuCheckboxRef.current) {
menuCheckboxRef.current.checked = false;
}
};

return (
<Headroom>
<header className={isDark ? "dark-menu header" : "header"}>
Expand All @@ -32,7 +40,12 @@ function Header() {
<span className="logo-name">{greeting.username}</span>
<span className="grey-color">/&gt;</span>
</a>
<input className="menu-btn" type="checkbox" id="menu-btn" />
<input
className="menu-btn"
type="checkbox"
id="menu-btn"
ref={menuCheckboxRef}
/>
<label
className="menu-icon"
htmlFor="menu-btn"
Expand Down Expand Up @@ -82,7 +95,7 @@ function Header() {
<li>
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
<a>
<ToggleSwitch />
<ToggleSwitch handleMenuItemClick={handleMenuItemClick} />
</a>
</li>
</ul>
Expand Down
Loading