Holiday Notice: Support will be provided on a limited scale from December 24th, 2024, to January 2nd, 2025. Happy holidays and a wonderful New Year!


Topic: Dropdown does not display selected value

SamV free asked 5 years ago


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 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



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: 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