Improve accessibility for navigation on web (#6120)

* improve accessibility for bottom bar tabs

* improve a11y for left nav

* group main content into <main>

* use flex_1 rather than absoluteFill
This commit is contained in:
Samuel Newman
2024-11-05 16:48:36 +00:00
committed by GitHub
parent 9772116343
commit b0c5a37daa
4 changed files with 169 additions and 69 deletions
+2 -2
View File
@@ -200,7 +200,7 @@ export function BottomBar({navigation}: BottomTabBarProps) {
accessibilityLabel={_(msg`Chat`)} accessibilityLabel={_(msg`Chat`)}
accessibilityHint={ accessibilityHint={
numUnreadMessages.count > 0 numUnreadMessages.count > 0
? `${numUnreadMessages.numUnread} unread` ? _(msg`${numUnreadMessages.numUnread} unread items`)
: '' : ''
} }
/> />
@@ -227,7 +227,7 @@ export function BottomBar({navigation}: BottomTabBarProps) {
accessibilityHint={ accessibilityHint={
numUnreadNotifications === '' numUnreadNotifications === ''
? '' ? ''
: `${numUnreadNotifications} unread` : _(msg`${numUnreadNotifications} unread items`)
} }
/> />
<Btn <Btn
+61 -45
View File
@@ -1,18 +1,14 @@
import React from 'react' import React from 'react'
import {View} from 'react-native' import {View} from 'react-native'
import Animated from 'react-native-reanimated' import Animated from 'react-native-reanimated'
import {useSafeAreaInsets} from 'react-native-safe-area-context'
import {msg, Trans} from '@lingui/macro' import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {useNavigationState} from '@react-navigation/native' import {useNavigationState} from '@react-navigation/native'
import {useMinimalShellFooterTransform} from '#/lib/hooks/useMinimalShellTransform' import {useMinimalShellFooterTransform} from '#/lib/hooks/useMinimalShellTransform'
import {usePalette} from '#/lib/hooks/usePalette'
import {clamp} from '#/lib/numbers'
import {getCurrentRoute, isTab} from '#/lib/routes/helpers' import {getCurrentRoute, isTab} from '#/lib/routes/helpers'
import {makeProfileLink} from '#/lib/routes/links' import {makeProfileLink} from '#/lib/routes/links'
import {CommonNavigatorParams} from '#/lib/routes/types' import {CommonNavigatorParams} from '#/lib/routes/types'
import {s} from '#/lib/styles'
import {useUnreadMessageCount} from '#/state/queries/messages/list-converations' import {useUnreadMessageCount} from '#/state/queries/messages/list-converations'
import {useUnreadNotifications} from '#/state/queries/notifications/unread' import {useUnreadNotifications} from '#/state/queries/notifications/unread'
import {useSession} from '#/state/session' import {useSession} from '#/state/session'
@@ -23,6 +19,7 @@ import {Link} from '#/view/com/util/Link'
import {Text} from '#/view/com/util/text/Text' import {Text} from '#/view/com/util/text/Text'
import {Logo} from '#/view/icons/Logo' import {Logo} from '#/view/icons/Logo'
import {Logotype} from '#/view/icons/Logotype' import {Logotype} from '#/view/icons/Logotype'
import {atoms as a, useTheme} from '#/alf'
import { import {
Bell_Filled_Corner0_Rounded as BellFilled, Bell_Filled_Corner0_Rounded as BellFilled,
Bell_Stroke2_Corner0_Rounded as Bell, Bell_Stroke2_Corner0_Rounded as Bell,
@@ -46,8 +43,7 @@ import {styles} from './BottomBarStyles'
export function BottomBarWeb() { export function BottomBarWeb() {
const {_} = useLingui() const {_} = useLingui()
const {hasSession, currentAccount} = useSession() const {hasSession, currentAccount} = useSession()
const pal = usePalette('default') const t = useTheme()
const safeAreaInsets = useSafeAreaInsets()
const footerMinimalShellTransform = useMinimalShellFooterTransform() const footerMinimalShellTransform = useMinimalShellFooterTransform()
const {requestSwitchToAccount} = useLoggedOutViewControls() const {requestSwitchToAccount} = useLoggedOutViewControls()
const closeAllActiveElements = useCloseAllActiveElements() const closeAllActiveElements = useCloseAllActiveElements()
@@ -69,12 +65,12 @@ export function BottomBarWeb() {
return ( return (
<Animated.View <Animated.View
role="navigation"
style={[ style={[
styles.bottomBar, styles.bottomBar,
styles.bottomBarWeb, styles.bottomBarWeb,
pal.view, t.atoms.bg,
pal.border, t.atoms.border_contrast_low,
{paddingBottom: clamp(safeAreaInsets.bottom, 15, 30)},
footerMinimalShellTransform, footerMinimalShellTransform,
]}> ]}>
{hasSession ? ( {hasSession ? (
@@ -84,8 +80,9 @@ export function BottomBarWeb() {
const Icon = isActive ? HomeFilled : Home const Icon = isActive ? HomeFilled : Home
return ( return (
<Icon <Icon
aria-hidden={true}
width={iconWidth + 1} width={iconWidth + 1}
style={[styles.ctrlIcon, pal.text, styles.homeIcon]} style={[styles.ctrlIcon, t.atoms.text, styles.homeIcon]}
/> />
) )
}} }}
@@ -95,8 +92,9 @@ export function BottomBarWeb() {
const Icon = isActive ? MagnifyingGlassFilled : MagnifyingGlass const Icon = isActive ? MagnifyingGlassFilled : MagnifyingGlass
return ( return (
<Icon <Icon
aria-hidden={true}
width={iconWidth + 2} width={iconWidth + 2}
style={[styles.ctrlIcon, pal.text, styles.searchIcon]} style={[styles.ctrlIcon, t.atoms.text, styles.searchIcon]}
/> />
) )
}} }}
@@ -104,43 +102,41 @@ export function BottomBarWeb() {
{hasSession && ( {hasSession && (
<> <>
<NavItem routeName="Messages" href="/messages"> <NavItem
routeName="Messages"
href="/messages"
badge={
unreadMessageCount.count > 0
? unreadMessageCount.numUnread
: undefined
}>
{({isActive}) => { {({isActive}) => {
const Icon = isActive ? MessageFilled : Message const Icon = isActive ? MessageFilled : Message
return ( return (
<> <Icon
<Icon aria-hidden={true}
width={iconWidth - 1} width={iconWidth - 1}
style={[styles.ctrlIcon, pal.text, styles.messagesIcon]} style={[
/> styles.ctrlIcon,
{unreadMessageCount.count > 0 && ( t.atoms.text,
<View style={styles.notificationCount}> styles.messagesIcon,
<Text style={styles.notificationCountLabel}> ]}
{unreadMessageCount.numUnread} />
</Text>
</View>
)}
</>
) )
}} }}
</NavItem> </NavItem>
<NavItem routeName="Notifications" href="/notifications"> <NavItem
routeName="Notifications"
href="/notifications"
badge={notificationCountStr}>
{({isActive}) => { {({isActive}) => {
const Icon = isActive ? BellFilled : Bell const Icon = isActive ? BellFilled : Bell
return ( return (
<> <Icon
<Icon aria-hidden={true}
width={iconWidth} width={iconWidth}
style={[styles.ctrlIcon, pal.text, styles.bellIcon]} style={[styles.ctrlIcon, t.atoms.text, styles.bellIcon]}
/> />
{notificationCountStr !== '' && (
<View style={styles.notificationCount}>
<Text style={styles.notificationCountLabel}>
{notificationCountStr}
</Text>
</View>
)}
</>
) )
}} }}
</NavItem> </NavItem>
@@ -158,8 +154,13 @@ export function BottomBarWeb() {
const Icon = isActive ? UserCircleFilled : UserCircle const Icon = isActive ? UserCircleFilled : UserCircle
return ( return (
<Icon <Icon
aria-hidden={true}
width={iconWidth} width={iconWidth}
style={[styles.ctrlIcon, pal.text, styles.profileIcon]} style={[
styles.ctrlIcon,
t.atoms.text,
styles.profileIcon,
]}
/> />
) )
}} }}
@@ -184,7 +185,7 @@ export function BottomBarWeb() {
<View style={{flexDirection: 'row', alignItems: 'center', gap: 12}}> <View style={{flexDirection: 'row', alignItems: 'center', gap: 12}}>
<Logo width={32} /> <Logo width={32} />
<View style={{paddingTop: 4}}> <View style={{paddingTop: 4}}>
<Logotype width={80} fill={pal.text.color} /> <Logotype width={80} fill={t.atoms.text.color} />
</View> </View>
</View> </View>
@@ -193,7 +194,7 @@ export function BottomBarWeb() {
onPress={showCreateAccount} onPress={showCreateAccount}
accessibilityHint={_(msg`Sign up`)} accessibilityHint={_(msg`Sign up`)}
accessibilityLabel={_(msg`Sign up`)}> accessibilityLabel={_(msg`Sign up`)}>
<Text type="md" style={[{color: 'white'}, s.bold]}> <Text type="md" style={[{color: 'white'}, a.font_bold]}>
<Trans>Sign up</Trans> <Trans>Sign up</Trans>
</Text> </Text>
</Button> </Button>
@@ -203,7 +204,7 @@ export function BottomBarWeb() {
onPress={showSignIn} onPress={showSignIn}
accessibilityHint={_(msg`Sign in`)} accessibilityHint={_(msg`Sign in`)}
accessibilityLabel={_(msg`Sign in`)}> accessibilityLabel={_(msg`Sign in`)}>
<Text type="md" style={[pal.text, s.bold]}> <Text type="md" style={[t.atoms.text, a.font_bold]}>
<Trans>Sign in</Trans> <Trans>Sign in</Trans>
</Text> </Text>
</Button> </Button>
@@ -219,7 +220,9 @@ const NavItem: React.FC<{
children: (props: {isActive: boolean}) => React.ReactChild children: (props: {isActive: boolean}) => React.ReactChild
href: string href: string
routeName: string routeName: string
}> = ({children, href, routeName}) => { badge?: string
}> = ({children, href, routeName, badge}) => {
const {_} = useLingui()
const {currentAccount} = useSession() const {currentAccount} = useSession()
const currentRoute = useNavigationState(state => { const currentRoute = useNavigationState(state => {
if (!state) { if (!state) {
@@ -235,8 +238,21 @@ const NavItem: React.FC<{
: isTab(currentRoute.name, routeName) : isTab(currentRoute.name, routeName)
return ( return (
<Link href={href} style={styles.ctrl} navigationAction="navigate"> <Link
href={href}
style={[styles.ctrl, a.pb_lg]}
navigationAction="navigate"
aria-role="link"
aria-label={routeName}
accessible={true}>
{children({isActive})} {children({isActive})}
{!!badge && (
<View
style={styles.notificationCount}
aria-label={_(msg`${badge} unread items`)}>
<Text style={styles.notificationCountLabel}>{badge}</Text>
</View>
)}
</Link> </Link>
) )
} }
@@ -34,6 +34,7 @@ import {LoggedOut} from '#/view/com/auth/LoggedOut'
import {Deactivated} from '#/screens/Deactivated' import {Deactivated} from '#/screens/Deactivated'
import {Onboarding} from '#/screens/Onboarding' import {Onboarding} from '#/screens/Onboarding'
import {SignupQueued} from '#/screens/SignupQueued' import {SignupQueued} from '#/screens/SignupQueued'
import {atoms as a} from '#/alf'
import {BottomBarWeb} from './bottom-bar/BottomBarWeb' import {BottomBarWeb} from './bottom-bar/BottomBarWeb'
import {DesktopLeftNav} from './desktop/LeftNav' import {DesktopLeftNav} from './desktop/LeftNav'
import {DesktopRightNav} from './desktop/RightNav' import {DesktopRightNav} from './desktop/RightNav'
@@ -137,12 +138,14 @@ function NativeStackNavigator({
return ( return (
<NavigationContent> <NavigationContent>
<NativeStackView <View role="main" style={a.flex_1}>
{...rest} <NativeStackView
state={state} {...rest}
navigation={navigation} state={state}
descriptors={newDescriptors} navigation={navigation}
/> descriptors={newDescriptors}
/>
</View>
{isWeb && showBottomBar && <BottomBarWeb />} {isWeb && showBottomBar && <BottomBarWeb />}
{isWeb && !showBottomBar && ( {isWeb && !showBottomBar && (
<> <>
+97 -16
View File
@@ -151,6 +151,7 @@ interface NavItemProps {
} }
function NavItem({count, href, icon, iconFilled, label}: NavItemProps) { function NavItem({count, href, icon, iconFilled, label}: NavItemProps) {
const t = useTheme() const t = useTheme()
const {_} = useLingui()
const {currentAccount} = useSession() const {currentAccount} = useSession()
const {gtMobile, gtTablet} = useBreakpoints() const {gtMobile, gtTablet} = useBreakpoints()
const isTablet = gtMobile && !gtTablet const isTablet = gtMobile && !gtTablet
@@ -199,7 +200,7 @@ function NavItem({count, href, icon, iconFilled, label}: NavItemProps) {
// @ts-ignore web only -prf // @ts-ignore web only -prf
href={href} href={href}
dataSet={{noUnderline: 1}} dataSet={{noUnderline: 1}}
accessibilityRole="tab" role="link"
accessibilityLabel={label} accessibilityLabel={label}
accessibilityHint=""> accessibilityHint="">
<View <View
@@ -219,6 +220,9 @@ function NavItem({count, href, icon, iconFilled, label}: NavItemProps) {
{isCurrent ? iconFilled : icon} {isCurrent ? iconFilled : icon}
{typeof count === 'string' && count ? ( {typeof count === 'string' && count ? (
<Text <Text
accessibilityLabel={_(msg`${count} unread items`)}
accessibilityHint=""
accessible={true}
style={[ style={[
a.absolute, a.absolute,
a.text_xs, a.text_xs,
@@ -307,7 +311,7 @@ function ComposeBtn() {
<View style={[a.flex_row, a.pl_md, a.pt_xl]}> <View style={[a.flex_row, a.pl_md, a.pt_xl]}>
<Button <Button
disabled={isFetchingHandle} disabled={isFetchingHandle}
label={_(msg`New post`)} label={_(msg`Compose new post`)}
onPress={onPressCompose} onPress={onPressCompose}
size="large" size="large"
variant="solid" variant="solid"
@@ -331,8 +335,16 @@ function ChatNavItem() {
<NavItem <NavItem
href="/messages" href="/messages"
count={numUnreadMessages.numUnread} count={numUnreadMessages.numUnread}
icon={<Message style={pal.text} width={NAV_ICON_WIDTH} />} icon={
iconFilled={<MessageFilled style={pal.text} width={NAV_ICON_WIDTH} />} <Message style={pal.text} aria-hidden={true} width={NAV_ICON_WIDTH} />
}
iconFilled={
<MessageFilled
style={pal.text}
aria-hidden={true}
width={NAV_ICON_WIDTH}
/>
}
label={_(msg`Chat`)} label={_(msg`Chat`)}
/> />
) )
@@ -351,6 +363,7 @@ export function DesktopLeftNav() {
return ( return (
<View <View
role="navigation"
style={[ style={[
styles.leftNav, styles.leftNav,
isTablet && styles.leftNavTablet, isTablet && styles.leftNavTablet,
@@ -371,23 +384,57 @@ export function DesktopLeftNav() {
<NavItem <NavItem
href="/" href="/"
icon={<Home width={NAV_ICON_WIDTH} style={pal.text} />} icon={
iconFilled={<HomeFilled width={NAV_ICON_WIDTH} style={pal.text} />} <Home
aria-hidden={true}
width={NAV_ICON_WIDTH}
style={pal.text}
/>
}
iconFilled={
<HomeFilled
aria-hidden={true}
width={NAV_ICON_WIDTH}
style={pal.text}
/>
}
label={_(msg`Home`)} label={_(msg`Home`)}
/> />
<NavItem <NavItem
href="/search" href="/search"
icon={<MagnifyingGlass style={pal.text} width={NAV_ICON_WIDTH} />} icon={
<MagnifyingGlass
style={pal.text}
aria-hidden={true}
width={NAV_ICON_WIDTH}
/>
}
iconFilled={ iconFilled={
<MagnifyingGlassFilled style={pal.text} width={NAV_ICON_WIDTH} /> <MagnifyingGlassFilled
style={pal.text}
aria-hidden={true}
width={NAV_ICON_WIDTH}
/>
} }
label={_(msg`Search`)} label={_(msg`Search`)}
/> />
<NavItem <NavItem
href="/notifications" href="/notifications"
count={numUnreadNotifications} count={numUnreadNotifications}
icon={<Bell width={NAV_ICON_WIDTH} style={pal.text} />} icon={
iconFilled={<BellFilled width={NAV_ICON_WIDTH} style={pal.text} />} <Bell
aria-hidden={true}
width={NAV_ICON_WIDTH}
style={pal.text}
/>
}
iconFilled={
<BellFilled
aria-hidden={true}
width={NAV_ICON_WIDTH}
style={pal.text}
/>
}
label={_(msg`Notifications`)} label={_(msg`Notifications`)}
/> />
<ChatNavItem /> <ChatNavItem />
@@ -396,12 +443,14 @@ export function DesktopLeftNav() {
icon={ icon={
<Hashtag <Hashtag
style={pal.text as FontAwesomeIconStyle} style={pal.text as FontAwesomeIconStyle}
aria-hidden={true}
width={NAV_ICON_WIDTH} width={NAV_ICON_WIDTH}
/> />
} }
iconFilled={ iconFilled={
<HashtagFilled <HashtagFilled
style={pal.text as FontAwesomeIconStyle} style={pal.text as FontAwesomeIconStyle}
aria-hidden={true}
width={NAV_ICON_WIDTH} width={NAV_ICON_WIDTH}
/> />
} }
@@ -409,23 +458,55 @@ export function DesktopLeftNav() {
/> />
<NavItem <NavItem
href="/lists" href="/lists"
icon={<List style={pal.text} width={NAV_ICON_WIDTH} />} icon={
iconFilled={<ListFilled style={pal.text} width={NAV_ICON_WIDTH} />} <List
style={pal.text}
aria-hidden={true}
width={NAV_ICON_WIDTH}
/>
}
iconFilled={
<ListFilled
style={pal.text}
aria-hidden={true}
width={NAV_ICON_WIDTH}
/>
}
label={_(msg`Lists`)} label={_(msg`Lists`)}
/> />
<NavItem <NavItem
href={currentAccount ? makeProfileLink(currentAccount) : '/'} href={currentAccount ? makeProfileLink(currentAccount) : '/'}
icon={<UserCircle width={NAV_ICON_WIDTH} style={pal.text} />} icon={
<UserCircle
aria-hidden={true}
width={NAV_ICON_WIDTH}
style={pal.text}
/>
}
iconFilled={ iconFilled={
<UserCircleFilled width={NAV_ICON_WIDTH} style={pal.text} /> <UserCircleFilled
aria-hidden={true}
width={NAV_ICON_WIDTH}
style={pal.text}
/>
} }
label={_(msg`Profile`)} label={_(msg`Profile`)}
/> />
<NavItem <NavItem
href="/settings" href="/settings"
icon={<Settings width={NAV_ICON_WIDTH} style={pal.text} />} icon={
<Settings
aria-hidden={true}
width={NAV_ICON_WIDTH}
style={pal.text}
/>
}
iconFilled={ iconFilled={
<SettingsFilled width={NAV_ICON_WIDTH} style={pal.text} /> <SettingsFilled
aria-hidden={true}
width={NAV_ICON_WIDTH}
style={pal.text}
/>
} }
label={_(msg`Settings`)} label={_(msg`Settings`)}
/> />