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

Add paginationAccessibilityLabels for Improved Accessibility in Pagination #185

Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions src/components/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const Pagination: React.FC<PaginationProps> = ({
onPaginationSelectedIndex,
paginationTapDisabled = false,
e2eID = '',
paginationAccessibilityLabels = [],
}) => {
return (
<View style={[styles.container, paginationStyle]}>
Expand All @@ -55,6 +56,8 @@ export const Pagination: React.FC<PaginationProps> = ({
onPaginationSelectedIndex?.();
}}
disabled={paginationTapDisabled}
accessibilityLabel={paginationAccessibilityLabels[index]}
accessible={!!paginationAccessibilityLabels[index]}
/>
))}
</View>
Expand Down
5 changes: 5 additions & 0 deletions src/components/Pagination/PaginationProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,9 @@ export type PaginationProps = {
*
*/
e2eID?: string;
/**
* Accessibility labels for the pagination items.
* This is optional and used for screen readers.
*/
paginationAccessibilityLabels?: string[];
};
15 changes: 10 additions & 5 deletions src/components/Pagination/__snapshots__/test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ exports[`pagination renders all props 1`] = `
}
>
<View
accessibilityLabel="1"
accessible={true}
focusable={true}
isTVSelectable={true}
Expand All @@ -41,6 +42,7 @@ exports[`pagination renders all props 1`] = `
testID="_pagination_0"
/>
<View
accessibilityLabel="2"
accessible={true}
focusable={true}
isTVSelectable={true}
Expand All @@ -64,6 +66,7 @@ exports[`pagination renders all props 1`] = `
testID="_pagination_1"
/>
<View
accessibilityLabel="3"
accessible={true}
focusable={true}
isTVSelectable={true}
Expand All @@ -87,6 +90,7 @@ exports[`pagination renders all props 1`] = `
testID="_pagination_2"
/>
<View
accessibilityLabel="4"
accessible={true}
focusable={true}
isTVSelectable={true}
Expand All @@ -110,6 +114,7 @@ exports[`pagination renders all props 1`] = `
testID="_pagination_3"
/>
<View
accessibilityLabel="5"
accessible={true}
focusable={true}
isTVSelectable={true}
Expand Down Expand Up @@ -153,7 +158,7 @@ exports[`pagination renders correctly 1`] = `
}
>
<View
accessible={true}
accessible={false}
focusable={true}
isTVSelectable={true}
onClick={[Function]}
Expand All @@ -176,7 +181,7 @@ exports[`pagination renders correctly 1`] = `
testID="_pagination_0"
/>
<View
accessible={true}
accessible={false}
focusable={true}
isTVSelectable={true}
onClick={[Function]}
Expand All @@ -199,7 +204,7 @@ exports[`pagination renders correctly 1`] = `
testID="_pagination_1"
/>
<View
accessible={true}
accessible={false}
focusable={true}
isTVSelectable={true}
onClick={[Function]}
Expand All @@ -222,7 +227,7 @@ exports[`pagination renders correctly 1`] = `
testID="_pagination_2"
/>
<View
accessible={true}
accessible={false}
focusable={true}
isTVSelectable={true}
onClick={[Function]}
Expand All @@ -245,7 +250,7 @@ exports[`pagination renders correctly 1`] = `
testID="_pagination_3"
/>
<View
accessible={true}
accessible={false}
focusable={true}
isTVSelectable={true}
onClick={[Function]}
Expand Down
1 change: 1 addition & 0 deletions src/components/Pagination/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('pagination', () => {
paginationActiveColor="black"
paginationDefaultColor="white"
size={5}
paginationAccessibilityLabels={['1', '2', '3', '4', '5']}
/>,
);
expect(toJSON()).toMatchSnapshot();
Expand Down
2 changes: 2 additions & 0 deletions src/components/SwiperFlatList/SwiperFlatList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const SwiperFlatList = React.forwardRef(
viewabilityConfig = {},
disableGesture = false,
e2eID,
paginationAccessibilityLabels,
...props
}: SwiperFlatListProps<T1>,
ref: React.Ref<SwiperFlatListRefProps>,
Expand Down Expand Up @@ -288,6 +289,7 @@ export const SwiperFlatList = React.forwardRef(
onPaginationSelectedIndex={onPaginationSelectedIndex}
paginationTapDisabled={paginationTapDisabled}
e2eID={e2eID}
paginationAccessibilityLabels={paginationAccessibilityLabels}
/>
) : null}
</React.Fragment>
Expand Down
6 changes: 6 additions & 0 deletions src/components/SwiperFlatList/SwiperFlatListProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ export type SwiperFlatListProps<T> = Partial<FlatListProps<T>> & {
* Defaults to 'false'
*/
useReactNativeGestureHandler?: boolean;
/**
* Accessibility labels for the pagination items.
* This is optional and used for screen readers.
*/
paginationAccessibilityLabels?: string[];
} & Pick<
PaginationProps,
| 'paginationActiveColor'
Expand All @@ -162,5 +167,6 @@ export type SwiperFlatListProps<T> = Partial<FlatListProps<T>> & {
| 'paginationStyleItemInactive'
| 'onPaginationSelectedIndex'
| 'paginationTapDisabled'
| 'paginationAccessibilityLabels'
>;
//#endregion Pagination