Skip to content

Higher-Order Component to map aria-description to accessibilityHint, with web compatibility

License

Notifications You must be signed in to change notification settings

sjwall/react-native-aria-description

Repository files navigation

react-native-aria-description

Cross-platform aria-description.

npm version npm downloads GitHub license PRs Welcome

Maps aria-description to accessibilityHint on native and on web polyfills with aria-describedby to link to a hidden <p> containing the description.

If you pass aria-describedby on web as a prop it won't override it.

Installing

To install react-native-aria-description:

npm install react-native-aria-description

Using

Wrap your component with withAriaDescription:

import {View, Text, Button} from 'react-native'
+import {withAriaDescription} from 'react-native-aria-description'
+
+const CustomButton = withAriaDescription(Button, {web: {useEffect: true}})

export default function App() {
  return (
    <View>
      <Text>Open up App.tsx to start working on your app!</Text>
-      <Button
+      <CustomButton
        title="Press me"
-        accessibilityHint="Pressing this button will print a statement in the console."
+        aria-description="Pressing this button will print a statement in the console."
        onPress={() => console.log('button has been pressed')}
      />
    </View>
  )
}

{web: {useEffect: true}} is required on components that don't propagate the props into the web element.

If you want the web element to use aria-description instead of the aria-describedby polyfill then call with false: withAriaDescription(Button, {web: {replaceWithDescribedBy: false}}).

About

Higher-Order Component to map aria-description to accessibilityHint, with web compatibility

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project