@@ -2,12 +2,16 @@ import {useCallback, useMemo} from 'react';
2
2
import _ from 'lodash' ;
3
3
import { PickerProps , PickerValue } from '../types' ;
4
4
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
+ > {
6
10
items : { value : string | number ; label : string } [ ] | null | undefined ;
7
11
}
8
12
9
13
const usePickerLabel = ( props : UsePickerLabelProps ) => {
10
- const { value, items, getLabel, getItemLabel, placeholder} = props ;
14
+ const { value, items, getLabel, getItemLabel, placeholder, accessibilityLabel , accessibilityHint } = props ;
11
15
12
16
const getLabelsFromArray = useCallback ( ( value : PickerValue ) => {
13
17
const itemsByValue = _ . keyBy ( items , 'value' ) ;
@@ -41,10 +45,12 @@ const usePickerLabel = (props: UsePickerLabelProps) => {
41
45
const accessibilityInfo = useMemo ( ( ) => {
42
46
const label = _getLabel ( value ) ;
43
47
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` )
46
52
} ;
47
- } , [ value ] ) ;
53
+ } , [ value , accessibilityLabel , accessibilityHint ] ) ;
48
54
49
55
return {
50
56
getLabelsFromArray,
0 commit comments