Skip to content

Commit 0def025

Browse files
authored
Picker - do not ignore accessibility props (#2416)
* Picker - do not ignore accessibility props * Destruct
1 parent 18d46ab commit 0def025

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/components/picker/helpers/usePickerLabel.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ import {useCallback, useMemo} from 'react';
22
import _ from 'lodash';
33
import {PickerProps, PickerValue} from '../types';
44

5-
interface UsePickerLabelProps extends Pick<PickerProps, 'value' | 'getLabel' | 'getItemLabel' | 'placeholder'> {
5+
interface UsePickerLabelProps
6+
extends Pick<
7+
PickerProps,
8+
'value' | 'getLabel' | 'getItemLabel' | 'placeholder' | 'accessibilityLabel' | 'accessibilityHint'
9+
> {
610
items: {value: string | number; label: string}[] | null | undefined;
711
}
812

913
const usePickerLabel = (props: UsePickerLabelProps) => {
10-
const {value, items, getLabel, getItemLabel, placeholder} = props;
14+
const {value, items, getLabel, getItemLabel, placeholder, accessibilityLabel, accessibilityHint} = props;
1115

1216
const getLabelsFromArray = useCallback((value: PickerValue) => {
1317
const itemsByValue = _.keyBy(items, 'value');
@@ -41,10 +45,12 @@ const usePickerLabel = (props: UsePickerLabelProps) => {
4145
const accessibilityInfo = useMemo(() => {
4246
const label = _getLabel(value);
4347
return {
44-
accessibilityLabel: label ? `${placeholder}. selected. ${label}` : `Select ${placeholder}`,
45-
accessibilityHint: label ? 'Double tap to edit' : `Goes to ${placeholder}. Suggestions will be provided`
48+
accessibilityLabel:
49+
accessibilityLabel ?? (label ? `${placeholder}. selected. ${label}` : `Select ${placeholder}`),
50+
accessibilityHint:
51+
accessibilityHint ?? (label ? 'Double tap to edit' : `Goes to ${placeholder}. Suggestions will be provided`)
4652
};
47-
}, [value]);
53+
}, [value, accessibilityLabel, accessibilityHint]);
4854

4955
return {
5056
getLabelsFromArray,

src/components/picker/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ const Picker = React.forwardRef((props: PickerProps, ref) => {
8888
useSafeArea,
8989
migrate,
9090
migrateTextField,
91+
accessibilityLabel,
92+
accessibilityHint,
9193
...others
9294
} = themeProps;
9395
const {preset} = others;
@@ -121,6 +123,8 @@ const Picker = React.forwardRef((props: PickerProps, ref) => {
121123
items,
122124
getItemLabel,
123125
getLabel,
126+
accessibilityLabel,
127+
accessibilityHint,
124128
placeholder: themeProps.placeholder
125129
});
126130

0 commit comments

Comments
 (0)