Mobilens English

控件 · 输入

多行文本框

所有状态

何时出现
行为规则

    用法

    import { useState } from 'react';
    import { Button, View } from 'react-native';
    import { Textarea } from '@/components/mobilens/Textarea';
    
    export function DeliveryNoteForm({ onSave }: { onSave: (note: string) => void }) {
      const [note, setNote] = useState('');
      const [error, setError] = useState<string>();
    
      function save() {
        if (!note.trim()) {
          setError('Enter a delivery note.');
          return;
        }
        onSave(note);
      }
    
      return (
        <View>
          <Textarea
            label="Delivery note"
            value={note}
            onChangeText={(next) => {
              setNote(next);
              setError(undefined);
            }}
            placeholder="Where should we leave your package?"
            error={error}
            maxLength={240}
          />
          <Button title="Save note" onPress={save} />
        </View>
      );
    }
    

    API

    参数类型默认值说明
    label string – Visible label, also used as the accessible name of the native text area.
    value string – The current text. Line breaks are preserved.
    onChangeText (text: string) => void – Receives edits and pasted text, including line breaks.
    onEndEditing? () => void – Called once editing ends; the Return key still inserts a new line.
    placeholder? string – Example shown while the text area is empty.
    helper? string – Help shown under the text area.
    error? string – Validation message, shown in place of help text.
    disabled? boolean false Makes the field read-only and dims it.
    maxLength? number – Native character limit; shows the length and limit below the input.
    autoFocus? boolean false Focus the text area when it mounts.
    ref? Ref<ComponentRef<typeof TextInput>> – Native input handle, for calling focus or blur.