Skip to content

Commit c26d9bf

Browse files
adellostedmnplb
andauthored
chore: [IOPAE-1728] Improve accessibility on SearchInput component (#416)
## Short description This PR improves the accessibility of the `SearchInput` component. ## List of changes proposed in this pull request - added `importantForAccessibility` prop to make the input field inaccessible when the component is pressable. This change ensures that the input is not announced by SR when the component is intended to be used as a button. Co-authored-by: Damiano Plebani <[email protected]>
1 parent eccf767 commit c26d9bf

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/components/searchInput/SearchInput.tsx

+10-6
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,15 @@ export const SearchInput = forwardRef<SearchInputRef, SearchInputProps>(
214214
: inputWidth;
215215
};
216216

217-
const cancel = useCallback(
217+
const handleCancel = useCallback(
218218
(event: GestureResponderEvent) => {
219219
onChangeText?.("");
220220
onCancel?.(event);
221221
},
222222
[onCancel, onChangeText]
223223
);
224224

225-
const clear = useCallback(() => {
225+
const handleClear = useCallback(() => {
226226
onChangeText?.("");
227227
searchInputRef.current?.clear();
228228
}, [onChangeText]);
@@ -233,7 +233,10 @@ export const SearchInput = forwardRef<SearchInputRef, SearchInputProps>(
233233
);
234234

235235
const renderSearchBar = () => (
236-
<Animated.View style={styles.searchBar}>
236+
<Animated.View
237+
importantForAccessibility={pressable ? "no-hide-descendants" : "auto"}
238+
style={styles.searchBar}
239+
>
237240
<Animated.View
238241
style={[styles.searchInput, animatedStyle]}
239242
pointerEvents={pressable ? "none" : "auto"}
@@ -279,7 +282,7 @@ export const SearchInput = forwardRef<SearchInputRef, SearchInputProps>(
279282
/>
280283
<AnimatedPressable
281284
style={[styles.clearButton, clearButtonAnimatedStyle]}
282-
onPress={clear}
285+
onPress={handleClear}
283286
accessibilityLabel={clearAccessibilityLabel}
284287
accessibilityRole="button"
285288
hitSlop={16}
@@ -294,7 +297,7 @@ export const SearchInput = forwardRef<SearchInputRef, SearchInputProps>(
294297
<Pressable
295298
accessibilityRole="button"
296299
accessibilityLabel={cancelButtonLabel}
297-
onPress={cancel}
300+
onPress={handleCancel}
298301
>
299302
<IOText
300303
color={theme["interactiveElem-default"]}
@@ -316,9 +319,10 @@ export const SearchInput = forwardRef<SearchInputRef, SearchInputProps>(
316319

317320
return pressable ? (
318321
<Pressable
322+
accessible={true}
319323
accessibilityRole="button"
320324
accessibilityLabel={placeholder}
321-
onPress={pressable?.onPress}
325+
onPress={pressable.onPress}
322326
>
323327
{renderSearchBar()}
324328
</Pressable>

0 commit comments

Comments
 (0)