Mobilens English

控件 · 输入

浮动标签输入框

输入框样式

所有状态

何时出现
行为规则

    用法

    import { useState } from 'react';
    import { FloatingInput } from '@/components/mobilens/FloatingInput';
    
    export function ContactEmail({ onSubmit }: { onSubmit: (email: string) => void }) {
      const [email, setEmail] = useState('');
      const [error, setError] = useState<string>();
      function validate() {
        const valid = /^\S+@\S+\.\S+$/.test(email.trim());
        setError(valid ? undefined : 'Enter a valid email address.');
        return valid;
      }
      return (
        <FloatingInput
          variant="outlined"
          label="Email"
          value={email}
          onChangeText={(next) => { setEmail(next); setError(undefined); }}
          error={error}
          placeholder="name@example.com"
          inputProps={{
            keyboardType: 'email-address', autoComplete: 'email', autoCapitalize: 'none', autoCorrect: false,
            returnKeyType: 'done', onBlur: validate, onSubmitEditing: () => { if (validate()) onSubmit(email.trim()); },
          }}
        />
      );
    }
    

    API

    参数类型默认值说明
    label string – Visible label and accessible name of the field.
    value string – Controlled text, including values inserted by paste or autofill.
    onChangeText (value: string) => void – Receives the text after an edit.
    variant? FloatingInputVariant 'outlined' Use an outlined notch, a bottom line, or a filled surface.
    placeholder? string – Example shown inside the field once the label is raised.
    helper? string – Help message displayed below the field.
    error? string – Validation message that replaces the helper.
    disabled? boolean false Prevents editing and dims the field.
    maxLength? number – Maximum number of characters; also shows the current count.
    autoFocus? boolean – Focus the input when mounted.
    inputProps? Omit<TextInputProps, 'value' | 'onChangeText' | 'editable' | 'placeholder' | 'maxLength' | 'autoFocus' | 'style' | 'multiline'> – Keyboard, autofill, return-key and input event settings.
    ref? Ref<ComponentRef<typeof TextInput>> – Native input handle for focus and blur.