From a071b7c26548c896bf80a9655a8b12eaf87833c2 Mon Sep 17 00:00:00 2001 From: Athou Date: Sat, 3 Aug 2024 11:30:29 +0200 Subject: [PATCH] add aria-label to action buttons (#1507) --- .../src/components/ActionButton.tsx | 30 +++++++++++++++---- .../components/content/FeedEntryFooter.tsx | 14 ++++----- .../src/components/header/Header.tsx | 18 +++++------ .../components/header/MarkAllAsReadButton.tsx | 4 +-- commafeed-client/src/pages/WelcomePage.tsx | 12 ++++---- commafeed-client/src/pages/app/Layout.tsx | 4 +-- 6 files changed, 51 insertions(+), 31 deletions(-) diff --git a/commafeed-client/src/components/ActionButton.tsx b/commafeed-client/src/components/ActionButton.tsx index 3e86d4ce..6d8ab3a4 100644 --- a/commafeed-client/src/components/ActionButton.tsx +++ b/commafeed-client/src/components/ActionButton.tsx @@ -1,3 +1,5 @@ +import type { MessageDescriptor } from "@lingui/core" +import { useLingui } from "@lingui/react" import { ActionIcon, Button, type ButtonVariant, Tooltip, useMantineTheme } from "@mantine/core" import type { ActionIconVariant } from "@mantine/core/lib/components/ActionIcon/ActionIcon" import { Constants } from "app/constants" @@ -7,7 +9,7 @@ import { type MouseEventHandler, type ReactNode, forwardRef } from "react" interface ActionButtonProps { className?: string icon?: ReactNode - label: ReactNode + label?: string | MessageDescriptor onClick?: MouseEventHandler variant?: ActionIconVariant & ButtonVariant hideLabelOnDesktop?: boolean @@ -20,17 +22,35 @@ interface ActionButtonProps { export const ActionButton = forwardRef((props: ActionButtonProps, ref) => { const { mobile } = useActionButton() const theme = useMantineTheme() + const { _ } = useLingui() + + const label = typeof props.label === "string" ? props.label : props.label && _(props.label) const variant = props.variant ?? "subtle" const iconOnly = (mobile && !props.showLabelOnMobile) || (!mobile && props.hideLabelOnDesktop) return iconOnly ? ( - - + + {props.icon} ) : ( - ) }) diff --git a/commafeed-client/src/components/content/FeedEntryFooter.tsx b/commafeed-client/src/components/content/FeedEntryFooter.tsx index 86b061e9..103daa57 100644 --- a/commafeed-client/src/components/content/FeedEntryFooter.tsx +++ b/commafeed-client/src/components/content/FeedEntryFooter.tsx @@ -1,4 +1,4 @@ -import { Trans, t } from "@lingui/macro" +import { msg, t } from "@lingui/macro" import { Group, Indicator, Popover, TagsInput } from "@mantine/core" import { markEntriesUpToEntry, markEntry, starEntry, tagEntry } from "app/entries/thunks" import { useAppDispatch, useAppSelector } from "app/store" @@ -40,13 +40,13 @@ export function FeedEntryFooter(props: FeedEntryFooterProps) { {props.entry.markable && ( : } - label={props.entry.read ? Keep unread : Mark as read} + label={props.entry.read ? msg`Keep unread` : msg`Mark as read`} onClick={readStatusButtonClicked} /> )} : } - label={props.entry.starred ? Unstar : Star} + label={props.entry.starred ? msg`Unstar` : msg`Star`} onClick={async () => await dispatch( starEntry({ @@ -59,7 +59,7 @@ export function FeedEntryFooter(props: FeedEntryFooterProps) { - } label={Share} /> + } label={msg`Share`} /> @@ -70,7 +70,7 @@ export function FeedEntryFooter(props: FeedEntryFooterProps) { - } label={Tags} /> + } label={msg`Tags`} /> @@ -88,13 +88,13 @@ export function FeedEntryFooter(props: FeedEntryFooterProps) { )} - } label={Open link} /> + } label={msg`Open link`} /> } - label={Mark as read up to here} + label={msg`Mark as read up to here`} onClick={async () => await dispatch(markEntriesUpToEntry(props.entry))} /> diff --git a/commafeed-client/src/components/header/Header.tsx b/commafeed-client/src/components/header/Header.tsx index e9271ffd..43314462 100644 --- a/commafeed-client/src/components/header/Header.tsx +++ b/commafeed-client/src/components/header/Header.tsx @@ -1,4 +1,4 @@ -import { Trans, t } from "@lingui/macro" +import { msg, t } from "@lingui/macro" import { Box, Center, CloseButton, Divider, Group, Indicator, Popover, TextInput } from "@mantine/core" import { useForm } from "@mantine/form" import { reloadEntries, search, selectNextEntry, selectPreviousEntry } from "app/entries/thunks" @@ -77,7 +77,7 @@ export function Header() { } - label={Previous} + label={msg`Previous`} onClick={async () => await dispatch( selectPreviousEntry({ @@ -90,7 +90,7 @@ export function Header() { /> } - label={Next} + label={msg`Next`} onClick={async () => await dispatch( selectNextEntry({ @@ -106,7 +106,7 @@ export function Header() { } - label={Refresh} + label={msg`Refresh`} onClick={async () => await dispatch(reloadEntries())} /> @@ -115,19 +115,19 @@ export function Header() { : } - label={settings.readingMode === "all" ? All : Unread} + label={settings.readingMode === "all" ? msg`All` : msg`Unread`} onClick={async () => await dispatch(changeReadingMode(settings.readingMode === "all" ? "unread" : "all"))} /> : } - label={settings.readingOrder === "asc" ? Asc : Desc} + label={settings.readingOrder === "asc" ? msg`Asc` : msg`Desc`} onClick={async () => await dispatch(changeReadingOrder(settings.readingOrder === "asc" ? "desc" : "asc"))} /> - } label={Search} /> + } label={msg`Search`} /> @@ -153,12 +153,12 @@ export function Header() { } - label={Extension options} + label={msg`Extension options`} onClick={() => openSettingsPage()} /> } - label={Open CommaFeed} + label={msg`Open CommaFeed`} onClick={() => openAppInNewTab()} /> diff --git a/commafeed-client/src/components/header/MarkAllAsReadButton.tsx b/commafeed-client/src/components/header/MarkAllAsReadButton.tsx index 595dc46b..fd234b4f 100644 --- a/commafeed-client/src/components/header/MarkAllAsReadButton.tsx +++ b/commafeed-client/src/components/header/MarkAllAsReadButton.tsx @@ -1,4 +1,4 @@ -import { Trans } from "@lingui/macro" +import { Trans, msg } from "@lingui/macro" import { Button, Code, Group, Modal, Slider, Stack, Text } from "@mantine/core" import { markAllEntries } from "app/entries/thunks" @@ -91,7 +91,7 @@ export function MarkAllAsReadButton(props: { iconSize: number }) { - } label={Mark all as read} onClick={buttonClicked} /> + } label={msg`Mark all as read`} onClick={buttonClicked} /> ) } diff --git a/commafeed-client/src/pages/WelcomePage.tsx b/commafeed-client/src/pages/WelcomePage.tsx index 39caa053..2650056f 100644 --- a/commafeed-client/src/pages/WelcomePage.tsx +++ b/commafeed-client/src/pages/WelcomePage.tsx @@ -1,4 +1,4 @@ -import { Trans } from "@lingui/macro" +import { msg } from "@lingui/macro" import { Anchor, Box, Center, Container, Divider, Group, Image, Space, Title, useMantineColorScheme } from "@mantine/core" import { client } from "app/client" import { redirectToApiDocumentation, redirectToLogin, redirectToRegistration, redirectToRootCategory } from "app/redirect/thunks" @@ -38,7 +38,7 @@ export function WelcomePage() { {serverInfos?.demoAccountEnabled && (
Try the demo!} + label={msg`Try the demo!`} icon={} variant="outline" onClick={async () => await login.execute({ name: "demo", password: "demo" })} @@ -96,7 +96,7 @@ function Buttons() { return ( Log in} + label={msg`Log in`} icon={} variant="outline" onClick={async () => await dispatch(redirectToLogin())} @@ -104,7 +104,7 @@ function Buttons() { /> {serverInfos?.allowRegistrations && ( Sign up} + label={msg`Sign up`} icon={} variant="filled" onClick={async () => await dispatch(redirectToRegistration())} @@ -113,7 +113,7 @@ function Buttons() { )} Switch to light theme : Switch to dark theme} + label={dark ? msg`Switch to light theme` : msg`Switch to dark theme`} icon={colorScheme === "dark" ? : } onClick={() => toggleColorScheme()} hideLabelOnDesktop @@ -121,7 +121,7 @@ function Buttons() { {isBrowserExtensionPopup && ( Extension options} + label={msg`Extension options`} icon={} onClick={() => openSettingsPage()} hideLabelOnDesktop diff --git a/commafeed-client/src/pages/app/Layout.tsx b/commafeed-client/src/pages/app/Layout.tsx index d136a641..f47dab22 100644 --- a/commafeed-client/src/pages/app/Layout.tsx +++ b/commafeed-client/src/pages/app/Layout.tsx @@ -1,4 +1,4 @@ -import { Trans } from "@lingui/macro" +import { msg } from "@lingui/macro" import { ActionIcon, AppShell, Box, Center, Group, ScrollArea, Title, useMantineTheme } from "@mantine/core" import { Constants } from "app/constants" import { redirectToAdd, redirectToRootCategory } from "app/redirect/thunks" @@ -101,7 +101,7 @@ export default function Layout(props: LayoutProps) { const burger = ( Close menu : Open menu} + label={mobileMenuOpen ? msg`Close menu` : msg`Open menu`} icon={mobileMenuOpen ? : } onClick={() => dispatch(setMobileMenuOpen(!mobileMenuOpen))} />