Mobilens English

控件 · 输入

验证码输入框

验证码输入样式

所有状态

何时出现
行为规则

    用法

    import { useState } from 'react';
    import { OtpInput } from '@/components/mobilens/OtpInput';
    
    export function VerifyCode({ verify }: { verify: (code: string) => Promise<boolean> }) {
      const [code, setCode] = useState('');
      const [wrong, setWrong] = useState(false);
      const [checking, setChecking] = useState(false);
    
      return (
        <OtpInput
          variant="segmented"
          value={code}
          autoFocus
          error={wrong}
          disabled={checking}
          onChangeText={(next) => {
            setCode(next);
            setWrong(false);
          }}
          onFilled={async (full) => {
            setChecking(true);
            setWrong(!(await verify(full)));
            setChecking(false);
          }}
        />
      );
    }
    

    API

    参数类型默认值说明
    value string – Digits typed so far. Keep it in state and pass it back, like a TextInput.
    onChangeText (value: string) => void – Called with the new digits on every edit. Non-digits are already removed.
    onFilled? (code: string) => void – Called once each time the full code is entered.
    length? number 6 Number of digits.
    variant? OtpInputVariant 'segmented' Show each digit in its own cell or all digits inside one outline.
    error? boolean false Red outline and a shake. Clear it when the user edits the code.
    disabled? boolean false Disable editing, for example while the code is checked.
    autoFocus? boolean false Focus the field and bring up the number pad when the screen opens.
    accessibilityLabel? string – What screen readers announce for the field.
    ref? Ref<ComponentRef<typeof TextInput>> – The hidden field, to focus() or blur() it.

    用在这些流程里