Replace Focusable navigation wrappers with tabIndex-based focus handling

This commit is contained in:
Mike Cao committed 2026-08-02 19:42:53 -07:00
1 parent d336eba27d
commit 5d8cf10bf1
11 files changed
+133 -382

No files matched your search

-138
View File
@@ -1,138 +0,0 @@
import {
Column,
Icon,
Menu,
MenuItem,
MenuSection,
MenuSeparator,
MenuTrigger,
Popover,
Pressable,
Row,
SubmenuTrigger,
Text,
} from '@umami/react-zen';
import { ArrowRight } from 'lucide-react';
import type { Key } from 'react';
import { IconLabel } from '@/components/common/IconLabel';
import { useLoginQuery, useMessages, useMobile, useNavigation } from '@/components/hooks';
import { ChevronRight, User, Users } from '@/components/icons';
import { Switch } from '@/components/svg';
import { LAST_TEAM_CONFIG } from '@/lib/constants';
import { removeItem } from '@/lib/storage';
export interface TeamsButtonProps {
showText?: boolean;
onAction?: (id: any) => void;
}
export function NavButton({ showText = true }: TeamsButtonProps) {
const { user } = useLoginQuery();
const { t, labels } = useMessages();
const { teamId, router } = useNavigation();
const { isMobile } = useMobile();
const team = user?.teams?.find(({ id }) => id === teamId);
const selectedKeys = new Set([teamId || 'user']);
const label = teamId ? team?.name : user.username;
const cloudMode = !!process.env.cloudMode;
const getUrl = (url: string) => {
return cloudMode ? `${process.env.cloudUrl}${url}` : url;
};
const handleAction = async (key: Key) => {
if (key === 'user') {
removeItem(LAST_TEAM_CONFIG);
if (cloudMode) {
window.location.href = '/';
} else {
router.push('/');
}
}
};
const handleNavigate = (url: string) => {
if (cloudMode) {
window.location.href = url;
} else {
router.push(url);
}
};
return (
<MenuTrigger>
<Pressable>
<Row
alignItems="center"
justifyContent="space-between"
flexGrow={1}
padding
border
borderRadius
shadow="sm"
minHeight="40px"
role="button"
style={{ cursor: 'pointer', textWrap: 'nowrap', overflow: 'hidden', outline: 'none' }}
>
<Row alignItems="center" position="relative" gap maxHeight="40px">
<Icon>{teamId ? <Users /> : <User />}</Icon>
{showText && <Text>{label}</Text>}
</Row>
{showText && (
<Icon rotate={90} size="sm">
<ChevronRight />
</Icon>
)}
</Row>
</Pressable>
<Popover side="bottom" align="start">
<Column minWidth="300px">
<Menu>
<SubmenuTrigger>
<MenuItem id="teams" showChecked={false} showSubMenuIcon>
<IconLabel icon={<Switch />} label={t(labels.switchAccount)} />
</MenuItem>
<Popover side={isMobile ? 'bottom' : 'right'} align="start">
<Column minWidth="300px">
<Menu selectionMode="single" selectedKeys={selectedKeys}>
<MenuSection title={t(labels.myAccount)}>
<MenuItem id="user" onAction={handleAction}>
<IconLabel icon={<User />} label={user.username} />
</MenuItem>
</MenuSection>
<MenuSeparator />
<MenuSection title={t(labels.teams)}>
{user?.teams?.map(({ id, name }) => (
<MenuItem
key={id}
id={id}
onAction={() => handleNavigate(getUrl(`/teams/${id}`))}
>
<IconLabel icon={<Users />}>
<Text wrap="nowrap">{name}</Text>
</IconLabel>
</MenuItem>
))}
{user?.teams?.length === 0 && (
<MenuItem id="manage-teams">
<a href="/settings/teams" style={{ width: '100%' }}>
<Row alignItems="center" justifyContent="space-between" gap>
<Text align="center">Manage teams</Text>
<Icon>
<ArrowRight />
</Icon>
</Row>
</a>
</MenuItem>
)}
</MenuSection>
</Menu>
</Column>
</Popover>
</SubmenuTrigger>
</Menu>
</Column>
</Popover>
</MenuTrigger>
);
}
+16 -17
View File
@@ -1,4 +1,4 @@
import { Focusable, Grid, Row, Text, Tooltip, TooltipTrigger } from '@umami/react-zen';
import { Grid, Row, Text, Tooltip, TooltipTrigger } from '@umami/react-zen';
import { addHours, format, startOfDay } from 'date-fns';
import { Fragment } from 'react';
import { LoadingPanel } from '@/components/common/LoadingPanel';
@@ -77,26 +77,25 @@ export function WeeklyTraffic({ websiteId }: { websiteId: string }) {
{day?.map((count: number, j) => {
const pct = max ? count / max : 0;
const cell = (
<Focusable>
<Row
tabIndex={0}
alignItems="center"
justifyContent="center"
backgroundColor="surface-raised"
width="16px"
height="16px"
borderRadius="full"
style={{ margin: '0 auto' }}
role="button"
>
<Row
alignItems="center"
justifyContent="center"
backgroundColor="surface-raised"
backgroundColor="primary"
width="16px"
height="16px"
borderRadius="full"
style={{ margin: '0 auto' }}
role="button"
>
<Row
backgroundColor="primary"
width="16px"
height="16px"
borderRadius="full"
style={{ opacity: pct, transform: `scale(${pct})` }}
/>
</Row>
</Focusable>
style={{ opacity: pct, transform: `scale(${pct})` }}
/>
</Row>
);
if (count <= 0) {