fix: improve user experience of bottom navigation (#1739)

This change improves bottom navigation in the following ways:
- Adds labels and proper ARIA handling
- Highlights active item (including related subpages)
- Adds badge support from System page
- Fixes to stay above page content.

Co-authored-by: Corey Vaillancourt <coreyjv@gmail.com>
This commit is contained in:
Corey Vaillancourt
2026-03-27 11:49:24 -04:00
committed by GitHub
parent 29b635e89c
commit 18dd66cb6e

View File

@@ -1,30 +1,60 @@
import { AppBar, IconButton, Toolbar } from '@mui/material';
import { Link } from '@tanstack/react-router';
import React from 'react';
import {
Badge,
BottomNavigation,
BottomNavigationAction,
Paper,
} from '@mui/material';
import { Link, useRouterState } from '@tanstack/react-router';
import { useNavItems } from '../hooks/useNavItems.tsx';
const getBaseSection = (path: string) => '/' + path.split('/')[1];
export const BottomNavBar = () => {
const navItems = useNavItems();
const pathname = useRouterState({ select: (s) => s.location.pathname });
const currentSection = getBaseSection(pathname);
const activeItem = navItems
.filter((item) => !item.hidden)
.find((item) => getBaseSection(item.path) === currentSection);
return (
<AppBar position="fixed" sx={{ top: 'auto', bottom: 0 }}>
<Toolbar sx={{ display: 'flex', justifyContent: 'space-around' }}>
<Paper
sx={{
position: 'fixed',
bottom: 0,
left: 0,
right: 0,
zIndex: (theme) => theme.zIndex.appBar,
}}
elevation={3}
>
<BottomNavigation value={activeItem?.path ?? false} showLabels>
{navItems
.filter((item) => !item.hidden)
.map((item) => (
<React.Fragment key={item.name}>
<IconButton
to={item.path}
key={item.name}
component={Link}
sx={{ display: 'inline-block' }}
color="inherit"
>
{item.icon}
</IconButton>
</React.Fragment>
<BottomNavigationAction
key={item.name}
label={item.name}
value={item.path}
sx={{ minWidth: 0, flex: 1 }}
icon={
item.badge ? (
<Badge
badgeContent={item.badge.count}
color={item.badge.color}
>
{item.icon}
</Badge>
) : (
item.icon
)
}
component={Link}
to={item.path}
/>
))}
</Toolbar>
</AppBar>
</BottomNavigation>
</Paper>
);
};