|
1 |
| -import React, {useCallback, useState, forwardRef, PropsWithChildren, useImperativeHandle} from 'react'; |
2 |
| - |
| 1 | +import React, {useCallback, useState, forwardRef, PropsWithChildren, useImperativeHandle, useRef} from 'react'; |
| 2 | +import {AccessibilityInfo, findNodeHandle} from 'react-native'; |
3 | 3 | import TouchableOpacity, {TouchableOpacityProps} from '../../components/touchableOpacity';
|
4 | 4 | import View from '../../components/view';
|
5 | 5 | import Modal, {ModalProps, ModalTopBarProps} from '../../components/modal';
|
@@ -68,14 +68,25 @@ const ExpandableOverlay = (props: ExpandableOverlayProps, ref: any) => {
|
68 | 68 | ...others
|
69 | 69 | } = props;
|
70 | 70 | const [visible, setExpandableVisible] = useState(false);
|
| 71 | + const containerRef = useRef(null); |
| 72 | + |
| 73 | + const focusAccessibility = useCallback(() => { |
| 74 | + const reactTag = findNodeHandle(containerRef.current); |
| 75 | + if (reactTag) { |
| 76 | + AccessibilityInfo.setAccessibilityFocus(reactTag); |
| 77 | + } |
| 78 | + }, []); |
| 79 | + |
71 | 80 | const openExpandable = useCallback(() => {
|
72 | 81 | setExpandableVisible(true);
|
73 | 82 | onPress?.(props);
|
74 | 83 | }, [onPress, customValue]);
|
| 84 | + |
75 | 85 | const closeExpandable = useCallback(() => {
|
76 | 86 | setExpandableVisible(false);
|
| 87 | + focusAccessibility(); |
77 | 88 | useDialog ? dialogProps?.onDismiss?.() : modalProps?.onDismiss?.();
|
78 |
| - }, [useDialog, dialogProps?.onDismiss, modalProps?.onDismiss]); |
| 89 | + }, [useDialog, dialogProps?.onDismiss, modalProps?.onDismiss, focusAccessibility]); |
79 | 90 |
|
80 | 91 | const toggleExpandable = useCallback(() => (visible ? closeExpandable() : openExpandable()),
|
81 | 92 | [visible, openExpandable, closeExpandable]);
|
@@ -126,7 +137,7 @@ const ExpandableOverlay = (props: ExpandableOverlayProps, ref: any) => {
|
126 | 137 | };
|
127 | 138 |
|
128 | 139 | return (
|
129 |
| - <TouchableOpacity {...others} onPress={openExpandable} disabled={disabled} testID={testID}> |
| 140 | + <TouchableOpacity ref={containerRef} {...others} onPress={openExpandable} disabled={disabled} testID={testID}> |
130 | 141 | <View pointerEvents="none">{children}</View>
|
131 | 142 | {renderOverlay()}
|
132 | 143 | </TouchableOpacity>
|
|
0 commit comments