Skip to content

Commit

Permalink
accessibility implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
CrisTofani committed Dec 5, 2023
1 parent 6c1cd39 commit 54b9a32
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/components/otpInput/OTPInput.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import * as React from "react";
import { useEffect, useState } from "react";
import { Pressable, TextInput } from "react-native";
import {
AccessibilityInfo,
Pressable,
TextInput,
findNodeHandle
} from "react-native";
import Animated from "react-native-reanimated";
import { IOStyles } from "../../core/IOStyles";
import { LabelSmall } from "../typography";
Expand Down Expand Up @@ -47,7 +52,7 @@ export const OTPInput = ({

const { translate, animatedStyle, shakeAnimation } = useErrorShakeAnimation();

const inputRef = React.useRef<TextInput>(null);
const inputRef = React.createRef<TextInput>();
const handleChange = (value: string) => {
if (value.length > length) {
return;
Expand Down Expand Up @@ -83,10 +88,16 @@ export const OTPInput = ({
<Pressable
onPress={() => {
inputRef.current?.focus();
const reactElem = findNodeHandle(inputRef.current);
if (reactElem) {
AccessibilityInfo.setAccessibilityFocus(reactElem);
}
setHasFocus(true);
}}
style={[IOStyles.row, { justifyContent: "space-around" }]}
accessible={false}
accessible={true}
accessibilityLabel="OTP Input"
accessibilityValue={{ text: inputValue }}
>
<TextInput
value={inputValue}
Expand Down

0 comments on commit 54b9a32

Please sign in to comment.