Skip to content

Commit

Permalink
Navbar: do not select the first value on unknown id (#2403)
Browse files Browse the repository at this point in the history
resolves #2401

Co-authored-by: Fred Lefévère-Laoide <[email protected]>
  • Loading branch information
FredLL-Avaiga and Fred Lefévère-Laoide authored Jan 17, 2025
1 parent f64ab3c commit 1632da3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
12 changes: 6 additions & 6 deletions frontend/taipy-gui/src/components/Taipy/NavBar.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ describe("NavBar Component", () => {
});
it("is disabled", async () => {
const { getAllByRole } = render(<BrowserRouter><NavBar lov={lov} active={false} /></BrowserRouter>);
const elts = getAllByRole("tab");
elts.forEach(elt => expect(elt).toBeDisabled());
const tabElements = getAllByRole("tab");
tabElements.forEach(elt => expect(elt).toBeDisabled());
});
it("is enabled by default", async () => {
const { getAllByRole } = render(<BrowserRouter><NavBar lov={lov} /></BrowserRouter>);
const elts = getAllByRole("tab");
elts.forEach(elt => expect(elt).not.toBeDisabled());
const tabElements = getAllByRole("tab");
tabElements.forEach(elt => expect(elt).not.toBeDisabled());
});
it("is enabled by active", async () => {
const { getAllByRole } = render(<BrowserRouter><NavBar lov={lov} active={true} /></BrowserRouter>);
const elts = getAllByRole("tab");
elts.forEach(elt => expect(elt).not.toBeDisabled());
const tabElements = getAllByRole("tab");
tabElements.forEach(elt => expect(elt).not.toBeDisabled());
});
it("dispatch a well formed message", async () => {
const focusSpy = jest.fn()
Expand Down
4 changes: 1 addition & 3 deletions frontend/taipy-gui/src/components/Taipy/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ const NavBar = (props: LovProps) => {
[state.locations, navigate]
);

const selectedVal =
lov.find((it) => getBaseURL() + it.id.substring(1) === location.pathname)?.id ||
(lov.length ? lov[0].id : false);
const selectedVal = lov.find((it) => getBaseURL() + it.id.substring(1) === location.pathname)?.id || "";

return isMobile ? (
<Tooltip title={hover || ""}>
Expand Down

0 comments on commit 1632da3

Please sign in to comment.