Skip to content

Commit b69bf40

Browse files
authored
Accessibility - add header reader after month change (#2604)
* Accessibility - add header reader after month change * remove console and add label arrows * Fix for Android not grouping on accessible parent
1 parent a739c0b commit b69bf40

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

src/calendar-list/index.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import findIndex from 'lodash/findIndex';
22
import PropTypes from 'prop-types';
33
import XDate from 'xdate';
44
import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState} from 'react';
5-
import {FlatList, FlatListProps, View, ViewStyle} from 'react-native';
5+
import {AccessibilityInfo, FlatList, FlatListProps, View, ViewStyle} from 'react-native';
6+
67
import {extractCalendarProps, extractHeaderProps} from '../componentUpdater';
78
import {parseDate, toMarkingFormat, xdateToData} from '../interface';
89
import {page, sameDate, sameMonth} from '../dateutils';
@@ -100,7 +101,9 @@ const CalendarList = (props: CalendarListProps & ContextProp, ref: any) => {
100101
contentContainerStyle,
101102
onEndReachedThreshold,
102103
onEndReached,
103-
onHeaderLayout
104+
onHeaderLayout,
105+
accessibilityElementsHidden,
106+
importantForAccessibility
104107
} = props;
105108

106109
const calendarProps = extractCalendarProps(props);
@@ -164,6 +167,7 @@ const CalendarList = (props: CalendarListProps & ContextProp, ref: any) => {
164167
const data = xdateToData(currMont);
165168
onMonthChange?.(data);
166169
onVisibleMonthsChange?.([data]);
170+
AccessibilityInfo.announceForAccessibility(currMont.toString('MMMM yyyy'));
167171
}
168172
}, [currentMonth]);
169173

@@ -271,9 +275,9 @@ const CalendarList = (props: CalendarListProps & ContextProp, ref: any) => {
271275
style={staticHeaderStyle}
272276
month={currentMonth}
273277
addMonth={addMonth}
274-
accessibilityElementsHidden={true} // iOS
275-
importantForAccessibility={'no-hide-descendants'} // Android
276278
onHeaderLayout={onHeaderLayoutToPass}
279+
accessibilityElementsHidden={accessibilityElementsHidden} // iOS
280+
importantForAccessibility={importantForAccessibility} // Android
277281
/>
278282
);
279283
}

src/calendar/header/index.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,11 @@ const CalendarHeader = forwardRef((props: CalendarHeaderProps, ref) => {
231231
}
232232

233233
const isLeft = direction === 'left';
234-
const arrowId = isLeft ? 'leftArrow' : 'rightArrow';
234+
const arrowDirection = isLeft ? 'left' : 'right';
235+
const arrowId = `${arrowDirection}Arrow`;
235236
const shouldDisable = isLeft ? disableArrowLeft : disableArrowRight;
236237
const onPress = !shouldDisable ? isLeft ? onPressLeft : onPressRight : undefined;
237238
const imageSource = isLeft ? require('../img/previous.png') : require('../img/next.png');
238-
const renderArrowDirection = isLeft ? 'left' : 'right';
239239

240240
return (
241241
<TouchableOpacity
@@ -244,12 +244,9 @@ const CalendarHeader = forwardRef((props: CalendarHeaderProps, ref) => {
244244
style={style.current.arrow}
245245
hitSlop={hitSlop}
246246
testID={`${testID}.${arrowId}`}
247+
importantForAccessibility={'no-hide-descendants'}
247248
>
248-
{renderArrow ? (
249-
renderArrow(renderArrowDirection)
250-
) : (
251-
<Image source={imageSource} style={shouldDisable ? style.current.disabledArrowImage : style.current.arrowImage}/>
252-
)}
249+
{renderArrow ? renderArrow(arrowDirection) : <Image source={imageSource} style={shouldDisable ? style.current.disabledArrowImage : style.current.arrowImage}/>}
253250
</TouchableOpacity>
254251
);
255252
};
@@ -275,6 +272,7 @@ const CalendarHeader = forwardRef((props: CalendarHeaderProps, ref) => {
275272
<View
276273
style={dayNamesStyle}
277274
testID={`${testID}.dayNames`}
275+
importantForAccessibility={'no-hide-descendants'}
278276
>
279277
{renderWeekNumbersSpace()}
280278
{renderWeekDays}
@@ -297,7 +295,7 @@ const CalendarHeader = forwardRef((props: CalendarHeaderProps, ref) => {
297295
>
298296
<View style={headerStyle}>
299297
{_renderArrow('left')}
300-
<View style={style.current.headerContainer}>
298+
<View style={style.current.headerContainer} importantForAccessibility={'no-hide-descendants'}>
301299
{_renderHeader()}
302300
{renderIndicator()}
303301
</View>

src/calendar/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import PropTypes from 'prop-types';
22
import XDate from 'xdate';
33
import isEmpty from 'lodash/isEmpty';
44
import React, {useRef, useState, useEffect, useCallback, useMemo} from 'react';
5-
import {View, ViewStyle, StyleProp} from 'react-native';
5+
import {AccessibilityInfo, View, ViewStyle, StyleProp} from 'react-native';
66
// @ts-expect-error
77
import GestureRecognizer, {swipeDirections} from 'react-native-swipe-gestures';
88
import constants from '../commons/constants';
@@ -108,6 +108,7 @@ const Calendar = (props: CalendarProps & ContextProp) => {
108108
const _currentMonth = currentMonth.clone();
109109
onMonthChange?.(xdateToData(_currentMonth));
110110
onVisibleMonthsChange?.([xdateToData(_currentMonth)]);
111+
AccessibilityInfo.announceForAccessibility(_currentMonth.toString('MMMM yyyy'));
111112
}, [currentMonth]);
112113

113114
const updateMonth = useCallback((newMonth: XDate) => {

0 commit comments

Comments
 (0)