Skip to content

Commit 0676664

Browse files
authored
Picker - useWheelPicker fix accessibility (#3696)
1 parent 57d95c3 commit 0676664

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

src/components/WheelPicker/Item.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ interface InternalProps<T> extends WheelPickerItemProps<T> {
2525
inactiveColor?: string;
2626
style?: TextStyle;
2727
onSelect: (index: number) => void;
28+
onPress?: () => void;
2829
centerH?: boolean;
2930
fakeLabel?: string;
3031
fakeLabelStyle?: TextStyle;
@@ -42,6 +43,7 @@ const WheelPickerItem = <T extends WheelPickerItemValue = number>(props: Interna
4243
fakeLabelProps,
4344
itemHeight,
4445
onSelect,
46+
onPress,
4547
offset,
4648
activeColor = Colors.$textPrimary,
4749
inactiveColor = Colors.$textNeutralHeavy,
@@ -76,6 +78,11 @@ const WheelPickerItem = <T extends WheelPickerItemValue = number>(props: Interna
7678
return [animatedColorStyle, style, fakeLabel ? textWithLabelPaddingStyle : styles.textPadding];
7779
}, [style, fakeLabel, animatedColorStyle, textWithLabelPaddingStyle]);
7880

81+
const _onPress = useCallback(() => {
82+
selectItem();
83+
onPress?.();
84+
}, [onPress, selectItem]);
85+
7986
const _fakeLabelStyle = useMemo(() => StyleSheet.flatten([fakeLabelStyle, styles.hidden]), [fakeLabelStyle]);
8087
return (
8188
<AnimatedTouchableOpacity
@@ -86,7 +93,7 @@ const WheelPickerItem = <T extends WheelPickerItemValue = number>(props: Interna
8693
centerH={align ? align === WheelPickerAlign.CENTER : centerH}
8794
right={align ? align === WheelPickerAlign.RIGHT : !centerH}
8895
left={align === WheelPickerAlign.LEFT}
89-
onPress={selectItem}
96+
onPress={_onPress}
9097
// @ts-ignore reanimated2
9198
index={index}
9299
testID={testID}

src/components/picker/PickerItemsList.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ const PickerItemsList = (props: PickerItemsListProps) => {
128128
);
129129
};
130130

131+
const onDonePress = useCallback(() => {
132+
context.onPress(wheelPickerValue);
133+
}, [context.onPress, wheelPickerValue]);
134+
131135
const renderPickerHeader = () => {
132136
const {cancelButtonProps, cancelLabel, doneLabel, title, titleStyle, containerStyle, onDone, onCancel} =
133137
topBarProps ?? {};
@@ -138,7 +142,14 @@ const PickerItemsList = (props: PickerItemsListProps) => {
138142
<View row spread padding-page style={containerStyle}>
139143
{(cancelButtonProps || cancelLabel) && renderCancel()}
140144
<Text style={titleStyle}>{title}</Text>
141-
<Text text70 $textPrimary accessibilityRole={'button'} onPress={() => context.onPress(wheelPickerValue)}>
145+
<Text
146+
text70
147+
$textPrimary
148+
accessibilityElementsHidden={useWheelPicker}
149+
importantForAccessibility={useWheelPicker ? 'no' : 'yes'}
150+
accessibilityRole={'button'}
151+
onPress={onDonePress}
152+
>
142153
{doneLabel ?? 'Select'}
143154
</Text>
144155
</View>

src/components/picker/index.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ const Picker = React.forwardRef((props: PickerProps, ref) => {
124124
items
125125
});
126126

127+
const accessibleFilteredItems = useMemo(() => {
128+
return filteredItems.map((item: PickerItemProps) => ({
129+
...item,
130+
onPress:
131+
useWheelPicker && Constants.accessibility.isScreenReaderEnabled ? () => onDoneSelecting(item.value) : undefined
132+
}));
133+
}, [useWheelPicker, filteredItems, onDoneSelecting]);
134+
127135
const {label, accessibilityInfo} = usePickerLabel({
128136
value,
129137
items,
@@ -247,7 +255,7 @@ const Picker = React.forwardRef((props: PickerProps, ref) => {
247255
useWheelPicker={useWheelPicker}
248256
mode={mode}
249257
useDialog={useDialog}
250-
items={useItems ? filteredItems : undefined}
258+
items={useItems ? accessibleFilteredItems : undefined}
251259
topBarProps={{
252260
...topBarProps,
253261
onCancel: cancelSelect,
@@ -266,7 +274,7 @@ const Picker = React.forwardRef((props: PickerProps, ref) => {
266274
renderCustomTopElement={renderCustomTopElement}
267275
selectionStatus={selectionStatus}
268276
>
269-
{filteredItems}
277+
{accessibleFilteredItems}
270278
</PickerItemsList>
271279
);
272280
}, [
@@ -285,7 +293,7 @@ const Picker = React.forwardRef((props: PickerProps, ref) => {
285293
renderCustomSearch,
286294
renderHeader,
287295
listProps,
288-
filteredItems,
296+
accessibleFilteredItems,
289297
useSafeArea,
290298
useWheelPicker,
291299
items,

0 commit comments

Comments
 (0)