Search code examples
reactjsreact-bootstrap

Checkboxes inside dropdown menu does not work in React


Nesting a checkboxes inside MenuItems inside a DropdownButton does not work; clicking the checkboxes has no effect:

<Dropdown.Item>
         <Form.Check
               name={"title"}
               type="switch"
               defaultChecked={props?.searchIn?.title}
               onChange={props?.handleSearchIn} />
</Dropdown.Item>

If try to invoke outside from DropDownMenu its working.


Solution

  • After struggling a lot for this problem, I found a simple solution. It can be useful for people who have this problem.

    If you put any input directly in Dropdown.Menu without using Dropdown.Item , it works correctly.

    <Dropdown.Menu>
             <Form.Check
                   name={"title"}
                   type="switch"
                   defaultChecked={props?.searchIn?.title}
                   onChange={props?.handleSearchIn} />
    </Dropdown.Menu>