diff --git a/src/components/FAB/FAB.tsx b/src/components/FAB/FAB.tsx index 961dfdd16b..cdb722e677 100644 --- a/src/components/FAB/FAB.tsx +++ b/src/components/FAB/FAB.tsx @@ -1,6 +1,8 @@ import * as React from 'react'; import { View } from 'react-native'; import type { + AccessibilityActionEvent, + AccessibilityActionInfo, ColorValue, GestureResponderEvent, PressableAndroidRippleConfig, @@ -78,6 +80,14 @@ export type Props = { * Indicates whether the element's controlled content is expanded. */ 'aria-expanded'?: boolean; + /** + * Custom actions screen reader users can trigger on the FAB. + */ + accessibilityActions?: readonly AccessibilityActionInfo[]; + /** + * Called with the name of the custom action the user triggered. + */ + onAccessibilityAction?: (event: AccessibilityActionEvent) => void; /** * Type of background drawable to display the feedback (Android). * https://reactnative.dev/docs/pressable#rippleconfig @@ -144,6 +154,8 @@ const FAB = ({ 'aria-selected': ariaSelected, 'aria-busy': ariaBusy, 'aria-expanded': ariaExpanded, + accessibilityActions, + onAccessibilityAction, background, style, testID, @@ -167,6 +179,8 @@ const FAB = ({ aria-selected={ariaSelected} aria-busy={ariaBusy} aria-expanded={ariaExpanded} + accessibilityActions={accessibilityActions} + onAccessibilityAction={onAccessibilityAction} background={background} style={style} testID={testID} diff --git a/src/components/FAB/Shell.tsx b/src/components/FAB/Shell.tsx index 01fe53496e..fa35a4d34a 100644 --- a/src/components/FAB/Shell.tsx +++ b/src/components/FAB/Shell.tsx @@ -1,6 +1,8 @@ import * as React from 'react'; import { Platform, StyleSheet, View } from 'react-native'; import type { + AccessibilityActionEvent, + AccessibilityActionInfo, ColorValue, GestureResponderEvent, PressableAndroidRippleConfig, @@ -121,6 +123,14 @@ export type ShellProps = { * Indicates whether the element's controlled content is expanded. */ 'aria-expanded'?: boolean; + /** + * Custom actions screen reader users can trigger on the FAB. + */ + accessibilityActions?: readonly AccessibilityActionInfo[]; + /** + * Called with the name of the custom action the user triggered. + */ + onAccessibilityAction?: (event: AccessibilityActionEvent) => void; /** * Largest scale the label font can reach (auto-built content only). */ @@ -214,6 +224,8 @@ const Shell = ({ 'aria-selected': ariaSelected, 'aria-busy': ariaBusy, 'aria-expanded': ariaExpanded, + accessibilityActions, + onAccessibilityAction, labelMaxFontSizeMultiplier, labelAnimatedStyle, background, @@ -485,6 +497,8 @@ const Shell = ({ aria-selected={ariaSelected} aria-busy={ariaBusy} aria-expanded={ariaExpanded} + accessibilityActions={accessibilityActions} + onAccessibilityAction={onAccessibilityAction} testID={testID} style={[children ? styles.fill : null, ...focusTarget.style]} > diff --git a/src/components/Switch/Switch.tsx b/src/components/Switch/Switch.tsx index c1024f29f0..c95da9895f 100644 --- a/src/components/Switch/Switch.tsx +++ b/src/components/Switch/Switch.tsx @@ -70,6 +70,10 @@ export type Props = { * Accessibility label for the switch. This is read by the screen reader when the user focuses the switch. */ 'aria-label'?: string; + /** + * ID of the element that names the switch, e.g. a `Text` with a `nativeID`. + */ + 'aria-labelledby'?: string; /** * Hides a non-interactive (`readOnly` or `disabled`) switch from assistive * technology, so it renders with no role and cannot take focus. Use it when @@ -150,6 +154,7 @@ const Switch = ({ testID, theme: themeOverrides, 'aria-label': ariaLabel, + 'aria-labelledby': ariaLabelledBy, 'aria-hidden': ariaHidden, }: Props) => { const theme = useInternalTheme(themeOverrides); @@ -497,6 +502,7 @@ const Switch = ({ role="switch" aria-checked={checked} aria-label={ariaLabel} + aria-labelledby={ariaLabelledBy} testID={testID} style={[ styles.touchable, diff --git a/src/components/__tests__/FAB.test.tsx b/src/components/__tests__/FAB.test.tsx index 8eb91a1efa..6f9e629d17 100644 --- a/src/components/__tests__/FAB.test.tsx +++ b/src/components/__tests__/FAB.test.tsx @@ -165,6 +165,23 @@ it('forwards event object to onPress', async () => { expect(onPress).toHaveBeenCalledWith({ key: 'value' }); }); +it('forwards accessibilityActions and onAccessibilityAction to the button', async () => { + const actions = [{ name: 'newNote', label: 'New note' }] as const; + const onAccessibilityAction = jest.fn(); + await render( + + ); + const button = screen.getByRole('button', { name: 'Add item' }); + expect(button).toHaveProp('accessibilityActions', actions); + expect(button).toHaveProp('onAccessibilityAction', onAccessibilityAction); +}); + it('calls onLongPress and onPressOut when FAB is long pressed', async () => { const user = userEvent.setup(); const onLongPress = jest.fn(); diff --git a/src/components/__tests__/Switch.test.tsx b/src/components/__tests__/Switch.test.tsx index bdd378a556..de796a78e3 100644 --- a/src/components/__tests__/Switch.test.tsx +++ b/src/components/__tests__/Switch.test.tsx @@ -129,6 +129,17 @@ describe('Switch accessibility', () => { expect(screen.getByRole('switch')).toBeOnTheScreen(); }); + it('forwards aria-labelledby to the switch', async () => { + await render( + + ); + + expect(screen.getByRole('switch')).toHaveProp( + 'aria-labelledby', + 'enabledLabel' + ); + }); + it('exposes a touch target meeting the 48dp minimum', async () => { await render();