Skip to content

Commit 5f197d9

Browse files
Merge pull request #115 from CodingItWrong/accessibility-labels
Button accessibility
2 parents 088b1b9 + 3e6cc66 commit 5f197d9

File tree

9 files changed

+29
-0
lines changed

9 files changed

+29
-0
lines changed

src/Date/CalendarHeader.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { StyleSheet, View } from 'react-native'
33
import { IconButton, useTheme } from 'react-native-paper'
44
import DayNames, { dayNamesHeight } from './DayNames'
55
import type { DisableWeekDaysType } from './dateUtils'
6+
import { getTranslation } from '../translations/utils'
67

78
const buttonContainerHeight = 56
89
const buttonContainerMarginTop = 4
@@ -48,6 +49,7 @@ function CalendarHeader({
4849
>
4950
<IconButton
5051
icon="chevron-left"
52+
accessibilityLabel={getTranslation(locale, 'previous')}
5153
onPress={onPrev}
5254
// RN types bug
5355
hasTVPreferredFocus={undefined}
@@ -63,6 +65,7 @@ function CalendarHeader({
6365
>
6466
<IconButton
6567
icon="chevron-right"
68+
accessibilityLabel={getTranslation(locale, 'next')}
6669
onPress={onNext}
6770
// RN types bug
6871
hasTVPreferredFocus={undefined}

src/Date/DatePickerModalContentHeader.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ export default function DatePickerModalContentHeader(
7979
{allowEditing ? (
8080
<IconButton
8181
icon={collapsed ? 'pencil' : 'calendar'}
82+
accessibilityLabel={
83+
collapsed
84+
? getTranslation(props.locale, 'typeInDate')
85+
: getTranslation(props.locale, 'pickDateFromCalendar')
86+
}
8287
color={color}
8388
onPress={onToggle}
8489
// RN types bug

src/Date/DatePickerModalHeader.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default function DatePickerModalHeader(
3131
<Appbar style={styles.appbarHeader}>
3232
<Appbar.Action
3333
icon="close"
34+
accessibilityLabel={getTranslation(locale, 'close')}
3435
onPress={props.onDismiss}
3536
color={color}
3637
testID="react-native-paper-dates-close"

src/Date/Day.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ function Day(props: {
7373
styles.button,
7474
{ backgroundColor: inRange ? selectColor : undefined },
7575
]}
76+
accessibilityRole="button"
7677
// RN types bug
7778
hasTVPreferredFocus={undefined}
7879
tvParallaxProperties={undefined}

src/Date/Month.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ function Month(props: MonthSingleProps | MonthRangeProps | MonthMultiProps) {
260260
<TouchableRipple
261261
disabled={!isHorizontal}
262262
onPress={isHorizontal ? () => onPressYear(year) : undefined}
263+
accessibilityRole="button"
264+
accessibilityLabel={`${monthName} ${year}`}
263265
style={[
264266
styles.yearButton,
265267
{

src/Date/YearPicker.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ function YearPure({
7474
<View style={styles.year}>
7575
<TouchableRipple
7676
onPress={() => onPressYear(year)}
77+
accessibilityRole="button"
78+
accessibilityLabel={String(year)}
7779
style={styles.yearButton}
7880
// RN types bug
7981
hasTVPreferredFocus={undefined}

src/translations/en.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,10 @@ const en: TranslationsType = {
1111
mustBeLowerThan: 'Must be earlier then',
1212
mustBeBetween: 'Must be between',
1313
dateIsDisabled: 'Day is not allowed',
14+
previous: 'Previous',
15+
next: 'Next',
16+
typeInDate: 'Type in date',
17+
pickDateFromCalendar: 'Pick date from calendar',
18+
close: 'Close',
1419
}
1520
export default en

src/translations/enGB.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,10 @@ const enGB: TranslationsType = {
1111
mustBeLowerThan: 'Must be earlier then',
1212
mustBeBetween: 'Must be between',
1313
dateIsDisabled: 'Day is not allowed',
14+
previous: 'Previous',
15+
next: 'Next',
16+
typeInDate: 'Type in date',
17+
pickDateFromCalendar: 'Pick date from calendar',
18+
close: 'Close',
1419
}
1520
export default enGB

src/translations/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ export type TranslationsType = {
88
mustBeLowerThan: string
99
mustBeBetween: string
1010
dateIsDisabled: string
11+
previous: string
12+
next: string
13+
typeInDate: string
14+
pickDateFromCalendar: string
15+
close: string
1116
}
1217

1318
let translationsPerLocale: Record<string, TranslationsType> = {}

0 commit comments

Comments
 (0)