Skip to content

Commit 5458cb7

Browse files
Fix: remove focus/highlight from Navbar after using browser back button
1 parent 6c5d6c6 commit 5458cb7

File tree

3 files changed

+185
-111
lines changed

3 files changed

+185
-111
lines changed

admin/src/components/Navbar.jsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
import React from "react";
1+
import React, { useEffect } from "react";
22
import { Button } from "./ui/button";
3-
import { ArrowRightFromLine, ChevronDown } from "lucide-react";
3+
import { ArrowRightFromLine } from "lucide-react";
44
import { Link, useLocation } from "react-router-dom";
55

6-
7-
8-
96
const Navbar = () => {
107
const location = useLocation();
8+
9+
useEffect(() => {
10+
// Remove focus/highlight from any active element when location changes
11+
if (document.activeElement) {
12+
document.activeElement.blur();
13+
}
14+
}, [location]);
15+
1116
return (
12-
<div className="px-[5vw] py-2 w-full flex justify-between items-center bg-green-900 text-white text-xl gap-5 z-10 sticky top-0 left-0 h-16">
17+
<div className="px-[5vw] py-2 w-full flex justify-between items-center bg-green-900 text-white text-xl gap-5 z-10 sticky top-0 left-0 h-16">
1318
<div className="flex gap-5">
1419
<Link to="/">
1520
<p>Home</p>
@@ -24,19 +29,14 @@ const Navbar = () => {
2429
<p>Contact Us</p>
2530
</div>
2631
<div className="flex gap-4">
27-
{location.pathname === "/login" ||
28-
location.pathname === "/userlogin" ? (
29-
<></>
30-
) : (
32+
{location.pathname !== "/login" && location.pathname !== "/userlogin" && (
3133
<Link to="/login">
3234
<Button className="gap-2 px-5 text-xl bg-green-500 hover:bg-white hover:text-black">
3335
LOGIN <ArrowRightFromLine />
3436
</Button>
3537
</Link>
3638
)}
37-
{location.pathname === "/register" ? (
38-
<></>
39-
) : (
39+
{location.pathname !== "/register" && (
4040
<Link to="/register">
4141
<Button className="text-xl bg-transparent hover:bg-white hover:text-black">
4242
REGISTER

employee/src/components/Navbar.jsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
import React from "react";
1+
import React, { useEffect } from "react";
22
import { Button } from "./ui/button";
3-
import { ArrowRightFromLine, ChevronDown } from "lucide-react";
3+
import { ArrowRightFromLine } from "lucide-react";
44
import { Link, useLocation } from "react-router-dom";
55

66
const Navbar = () => {
77
const location = useLocation();
8+
9+
useEffect(() => {
10+
// Remove focus/highlight from any active element when location changes
11+
if (document.activeElement) {
12+
document.activeElement.blur();
13+
}
14+
}, [location]);
15+
816
return (
9-
<div className="px-[5vw] py-2 w-full flex justify-between items-center bg-green-900 text-white text-xl gap-5 z-10 sticky top-0 left-0 h-16">
17+
<div className="px-[5vw] py-2 w-full flex justify-between items-center bg-green-900 text-white text-xl gap-5 z-10 sticky top-0 left-0 h-16">
1018
<div className="flex gap-5">
1119
<Link to="/">
1220
<p>Home</p>
@@ -21,19 +29,14 @@ const Navbar = () => {
2129
<p>Contact Us</p>
2230
</div>
2331
<div className="flex gap-4">
24-
{location.pathname === "/login" ||
25-
location.pathname === "/userlogin" ? (
26-
<></>
27-
) : (
32+
{location.pathname !== "/login" && location.pathname !== "/userlogin" && (
2833
<Link to="/login">
2934
<Button className="gap-2 px-5 text-xl bg-green-500 hover:bg-white hover:text-black">
3035
LOGIN <ArrowRightFromLine />
3136
</Button>
3237
</Link>
3338
)}
34-
{location.pathname === "/register" ? (
35-
<></>
36-
) : (
39+
{location.pathname !== "/register" && (
3740
<Link to="/register">
3841
<Button className="text-xl bg-transparent hover:bg-white hover:text-black">
3942
REGISTER

0 commit comments

Comments
 (0)