ExpandablePressable
ExpandablePressable is Pressable component that automatically handles the expanded accessibilityState
.
Usage
import { ExpandablePressable } from 'react-native-ama';
<ExpandablePressable
accessibilityLabel="I'm ExpandablePressable!"
expanded={isExpanded}
onPress={onPressa}>
<Text>I'm pressable</Text>
</ExpandablePressable>;
Example
import { ExpandablePressable, Text } from 'react-native-ama';
const Test = () => {
const [isExpanded, setIsExpanded] = React.useState(false);
return (
<>
<ExpandablePressable
accessibilityLabel={isExpanded ? 'Less' : 'More'}
expanded={isExpanded}
onPress={() => setIsExpanded(expanded => !expanded)}>
{isExpanded ? <MinumIcon /> : <PlusIcon />}
</ExpandablePressable>
{isExpanded ? <>{/* content goes here */}</> : null}
</>
);
};
Accessibility
The hook automatically:
- Sets
accessibilityRole
to button - Handles the
accessibilityState
for expanded
Compared to the default React Native component, this custom component:
- Forces the use of
accessibilityLabel
DEV only check - Performs a Minimum Size check DEV only check
- Performs a contrast checker between its background color and its children color DEV only check
accessibilityRole
The accessibilityRole
property is used by the screen reader to announce the kind of element focused on. If the property is omitted, the user might have little to no clue what could happen if the element is triggered.
accessibilityLabel
The accessibilityLabel
property is the first thing announced by the screen reader when the elements gain the focus; then, it announces its role. If the property is omitted, the user might have little to no clue what could happen if the element is triggered.
Contrast checker
The component performs a contrast check between its background colour and the children's foreground when in dev mode.
info
AMA does also perform a contrast check on disabled button, as a poor contrast can make them hard to read.
Minimum size
The component uses the onLayout prop to perform the minium size check.
Props
Required accessibilityLabel
The accessibilityLabel
Required expanded
Indicates whether an expandable element is currently expanded or collapsed.
Type | Default |
---|---|
boolean | undefined |