簡體   English   中英

react-bootstrap 如何使用自定義表單控件組件

[英]react-bootstrap how to use custom form control component

我需要在我的表單中添加選擇輸入,但是選項太多,所以默認的方式看起來真的很難看(

<Form.Control as="select">
    {props.options.map(
        (o) => <option>{o}</option>
    )}
</Form.Control>

所以我決定使用react-bootstrap-typeahead因為它已經在我的項目中使用並且它支持搜索。 但是,在這種情況下它不能正常工作。

<Form>
    <Form.Group>
        <Form.Label>Provider</Form.Label>
        <Form.Control
            as={Typeahead}
            id="id"
            options={props.options}
         />
    </Form.Group>
</Form>

它看起來像這樣: 在此處輸入圖片說明

可能我做得不對,但我不知道如何以另一種方式做到這一點(

https://react-bootstrap.github.io/components/forms/#form-control-props

那里有一個道具“as”。 見下面的例子。

export default function Input(props) { 

 const CustomFormControl = React.forwardRef(({ children, onChange}, ref) => (
    <>
     <p>Insert your elements for yout form</p>
     <p>{props.test}</p>
    </>
  ));

return (
    <>
        <Form.Control
        as = {CustomFormControl}
        test = {"hellow world"}
        /** and here u can inser the props you need **/
        />
    </>

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM