Topic: Dropdown does not display selected value
On the demo site and in my code, when using the MDBDropdown component, the selected value is not retained in the widget. How can I have the selected value displayed to the user after selection?
Jakub Chmura staff premium answered 5 years ago
Hi @SamV,
You need to control active
prop in the MDBDropdownItem
component. like in the snippet below. You need just write a function to toggle true
/ false
after click / keyDown on clicked element.
import React from "react";
import { MDBDropdown, MDBDropdownToggle, MDBDropdownMenu, MDBDropdownItem } from "mdbreact";
β
const DropdownPage = () => {
return (
<MDBDropdown dropright>
<MDBDropdownToggle caret color="primary">
Dropup
</MDBDropdownToggle>
<MDBDropdownMenu >
<MDBDropdownItem>Action</MDBDropdownItem>
<MDBDropdownItem active={true}>Another Action</MDBDropdownItem>
<MDBDropdownItem active={false}>Something else here</MDBDropdownItem>
<MDBDropdownItem divider />
<MDBDropdownItem active={true}>Separated link</MDBDropdownItem>
</MDBDropdownMenu>
</MDBDropdown>
);
}
β
export default DropdownPage;
Best regards,
Kuba
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- User: Free
- Premium support: No
- Technology: MDB React
- MDB Version: 4.22.0
- Device: thinkpad
- Browser: Chrome
- OS: Windows 10
- Provided sample code: No
- Provided link: No