1

I am implementing an input form and I am hoping that it could have a fix line limit. For example, for one box, it would be a 3-line input box. If more than 3 lines, there will be ideally a scroll bar on y-axis (i.e., no overflow in x axis). My current code is

<Form>
  <FormGroup>
    <ControlLabel>
      Label
    </ControlLabel>
    <InputGroup>
      <FormControl value='default' onChange={<some function>} />
    </InputGroup>

  </FormGroup>
</Form>

but it only rendered one line's input.

Edited: using textarea, the font seems to be very tiny. enter image description here

2 Answers 2

3

The following snippet fixes the described issue:

<Form.Group controlId="exampleForm.ControlTextarea1">
  <Form.Label>Example textarea</Form.Label>
  <Form.Control as="textarea" rows="3" />
</Form.Group>
Sign up to request clarification or add additional context in comments.

Comments

1

The componentClass prop of a FormControl is "input" by default, which renders a text input.

A text input is single line.

So try setting the componentClass prop of FormControl to "textarea":

<Form>
    <FormGroup>
        <ControlLabel>
            Label
        </ControlLabel>
        <InputGroup>
            <FormControl componentClass="textarea" value='default' onChange={<some function>} />
        </InputGroup>
    </FormGroup>
</Form>

3 Comments

Thanks! Is there a way I could limit the height of the text box (e.g., # of lines)?
Also, it seems like the text is very tiny. I edited my question with a snapshot. Could you take a look?
In html, textarea's number of rows is defined by the row prop: developer.mozilla.org/fr/docs/Web/HTML/Element/Textarea FormControl should accept this prop, look into React-bootstrap's documentation or do not use react-bootstrap. The font size is determined by css as in any other text element, adjust your css or look into reat-bootstrap documentation. You also may be able to set it with a style prop: style={{ fontSize: '14px' }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.