From 22f0c16cf1fe956ffbde331dad37eaa5270161de Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Wed, 10 Jan 2024 15:02:07 -0600 Subject: [PATCH] Enforce a11y props on buttons --- src/view/com/Button.tsx | 15 +++++++-- src/view/com/Link.tsx | 6 ++-- src/view/screens/DebugNew.tsx | 61 +++++++++++++++++++++++++++++------ 3 files changed, 67 insertions(+), 15 deletions(-) diff --git a/src/view/com/Button.tsx b/src/view/com/Button.tsx index 1d858a8eea..7b3beb7dca 100644 --- a/src/view/com/Button.tsx +++ b/src/view/com/Button.tsx @@ -5,6 +5,7 @@ import { PressableProps, TextProps, ViewStyle, + AccessibilityProps, } from 'react-native' import {useTheme, atoms, tokens, web, native} from '#/alf' @@ -22,7 +23,10 @@ export type VariantProps = { size?: ButtonSize } -export type ButtonProps = Omit & +export type ButtonProps = Omit< + PressableProps, + 'children' | 'style' | 'accessibilityLabel' | 'accessibilityHint' +> & VariantProps & { children: | ((props: { @@ -37,14 +41,17 @@ export type ButtonProps = Omit & }) => React.ReactNode) | React.ReactNode | string + accessibilityLabel: Required['accessibilityLabel'] + accessibilityHint: Required['accessibilityHint'] } export type ButtonTextProps = TextProps & VariantProps & {disabled?: boolean} export function Button({ children, - style, type, size, + accessibilityLabel, + accessibilityHint, disabled = false, ...rest }: ButtonProps) { @@ -179,6 +186,9 @@ export function Button({ () - const {href, accessibilityRole} = useLinkProps({ + const {href} = useLinkProps({ to: typeof to === 'string' ? convertBskyAppUrlIfNeeded(sanitizeUrl(to)) : to, }) @@ -139,9 +139,9 @@ export function Link({ return ( + - - - - - - External - +

External with custom children

https://blueskyweb.xyz Internal - + {({props}) => Link as a button}