mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Accessible active tab and nav landmark in MobileTabBar
This commit is contained in:
1 parent
a6cdbc378d
commit
27403cdef2
2 files changed
+33
-9
No files matched your search
@@ -195,19 +195,41 @@ describe('MobileTabBar', () => {
|
||||
it('Sessions tab is active when pathname is / and no sheet is open', () => {
|
||||
renderTabBar('/')
|
||||
|
||||
const sessionsButton = screen.getByText('Sessions').closest('button')
|
||||
expect(sessionsButton).toHaveClass('text-primary')
|
||||
const sessionsButton = screen.getByRole('button', { name: 'Sessions' })
|
||||
expect(sessionsButton).toHaveAttribute('aria-current', 'true')
|
||||
expect(sessionsButton).toHaveClass('text-foreground')
|
||||
expect(sessionsButton).toHaveClass('border-primary')
|
||||
expect(sessionsButton).not.toHaveClass('text-primary')
|
||||
expect(screen.getByRole('button', { name: 'Files' })).not.toHaveAttribute('aria-current')
|
||||
})
|
||||
|
||||
it('Sessions tab is active when openSheet is sessions regardless of pathname', () => {
|
||||
renderTabBar('/repos/123?mobileTab=sessions')
|
||||
|
||||
const sessionsButton = screen.getByText('Sessions').closest('button')
|
||||
expect(sessionsButton).toHaveClass('text-primary')
|
||||
const sessionsButton = screen.getByRole('button', { name: 'Sessions' })
|
||||
expect(sessionsButton).toHaveAttribute('aria-current', 'true')
|
||||
expect(sessionsButton).toHaveClass('text-foreground')
|
||||
expect(sessionsButton).toHaveClass('border-primary')
|
||||
})
|
||||
|
||||
it('wraps the global tabs in a Primary navigation landmark', () => {
|
||||
renderTabBar('/schedules')
|
||||
|
||||
const nav = screen.getByRole('navigation', { name: 'Primary navigation' })
|
||||
const schedulesButton = screen.getByRole('button', { name: 'Schedules' })
|
||||
expect(nav).toContainElement(schedulesButton)
|
||||
expect(schedulesButton).toHaveAttribute('aria-current', 'true')
|
||||
})
|
||||
|
||||
it('wraps the schedule tabs in a Schedule navigation landmark', () => {
|
||||
renderTabBar('/repos/123/schedules')
|
||||
|
||||
const nav = screen.getByRole('navigation', { name: 'Schedule navigation' })
|
||||
expect(nav).toContainElement(screen.getByRole('button', { name: 'Jobs' }))
|
||||
expect(screen.getByRole('button', { name: 'Jobs' })).toHaveAttribute('aria-current', 'true')
|
||||
expect(screen.getByRole('button', { name: 'Runs' })).not.toHaveAttribute('aria-current')
|
||||
})
|
||||
|
||||
it('does not render tab bar on SessionDetail path /repos/:id/sessions/:sid', () => {
|
||||
const { container } = renderTabBar('/repos/1/sessions/abc')
|
||||
|
||||
|
||||
@@ -192,21 +192,23 @@ function buildScheduleTabs(scheduleTab: ScheduleTab, setScheduleTab: (tab: Sched
|
||||
|
||||
interface TabBarRowProps {
|
||||
tabs: TabDef[]
|
||||
label: string
|
||||
}
|
||||
|
||||
const TabBarRow = memo(function TabBarRow({ tabs }: TabBarRowProps) {
|
||||
const TabBarRow = memo(function TabBarRow({ tabs, label }: TabBarRowProps) {
|
||||
return (
|
||||
<div className="fixed bottom-0 inset-x-0 z-40 flex border-t border-border bg-card/90 backdrop-blur-sm pb-safe">
|
||||
<nav aria-label={label} className="fixed bottom-0 inset-x-0 z-40 flex border-t border-border bg-card/90 backdrop-blur-sm pb-safe">
|
||||
{tabs.map((tab) => {
|
||||
const Icon = tab.icon
|
||||
return (
|
||||
<button
|
||||
key={tab.key}
|
||||
type="button"
|
||||
aria-current={tab.active ? 'true' : undefined}
|
||||
className={cn(
|
||||
'relative flex-1 flex flex-col items-center justify-center gap-1 px-2 py-2 text-xs font-medium border-b-2 transition-colors',
|
||||
tab.active
|
||||
? 'text-primary border-primary'
|
||||
? 'text-foreground border-primary'
|
||||
: 'text-muted-foreground border-transparent hover:text-foreground',
|
||||
)}
|
||||
onClick={tab.onClick}
|
||||
@@ -225,7 +227,7 @@ const TabBarRow = memo(function TabBarRow({ tabs }: TabBarRowProps) {
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</nav>
|
||||
)
|
||||
})
|
||||
|
||||
@@ -276,5 +278,5 @@ export const MobileTabBar = memo(function MobileTabBar() {
|
||||
if (!isMobile) return null
|
||||
if (routeState.mode === 'hidden') return null
|
||||
|
||||
return <TabBarRow tabs={tabs} />
|
||||
return <TabBarRow tabs={tabs} label={routeState.mode === 'schedule' ? 'Schedule navigation' : 'Primary navigation'} />
|
||||
})
|
||||
Reference in new issue
Block a user