Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(exoflex): supports a11y for collapsible #462

Merged
merged 1 commit into from
Apr 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions packages/exoflex/src/components/Collapsible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
TextStyle,
Platform,
View,
AccessibilityProps,
} from 'react-native';
import CollapsibleBase from 'react-native-collapsible';
import { useAnimation } from 'react-native-animation-hooks';
Expand All @@ -16,7 +17,7 @@ import AnimatedIcon from './AnimatedIcon';
import Text from './Text';
import useTheme from '../helpers/useTheme';

export type CollapsibleProps = {
export type CollapsibleProps = AccessibilityProps & {
title: string;
children: ReactNode;
style?: StyleProp<ViewStyle>;
Expand All @@ -27,6 +28,8 @@ export type CollapsibleProps = {
renderIconLeft?: null | ((animatedValue: Animated.Value) => ReactNode);
renderIconRight?: null | ((animatedValue: Animated.Value) => ReactNode);
disabled?: boolean;
// NOTE: Deprecated prop, remove `isCollapsed` on v4.0
isCollapsed?: boolean;
};

function Collapsible({
Expand All @@ -39,7 +42,11 @@ function Collapsible({
renderIconLeft,
renderIconRight,
disabled,
...otherProps
children,
isCollapsed: isCollapsedProp,
accessibilityRole,
accessibilityState,
...otherAccessibilityProps
}: CollapsibleProps) {
let { colors, style: themeStyle } = useTheme();
let [isCollapsed, setCollapsed] = useState(true);
Expand All @@ -55,7 +62,7 @@ function Collapsible({
duration: 300,
});

if (otherProps.hasOwnProperty('isCollapsed')) {
if (isCollapsedProp) {
// eslint-disable-next-line no-console
console.warn(
'`isCollapsed` props is deprecated. To control the Collapsible, please use Accordion component instead.',
Expand All @@ -75,6 +82,9 @@ function Collapsible({
]}
>
<TouchableOpacity
{...otherAccessibilityProps}
accessibilityRole={accessibilityRole || 'button'}
accessibilityState={{ expanded: !isCollapsed, ...accessibilityState }}
activeOpacity={0.9}
onPress={toggleCollapsible}
style={[
Expand Down Expand Up @@ -126,8 +136,9 @@ function Collapsible({
themeStyle?.collapsible?.contentContainerStyle,
contentContainerStyle,
]}
{...otherProps}
/>
>
{children}
</CollapsibleBase>
</View>
);
}
Expand Down