Topic: MDBDropDown Doesnt show selected value

afshinshahpari@gmail.com free asked 5 years ago


I need a dropdownlist that shows the value of selected item but your dropdown always shows the label.

Which control are you using for instance in current form that we choose : "Technology"?

Thanks


Konrad Stępień staff answered 5 years ago


Hi @afshinshahpari@gmail.com,

For what do you need MDBDropdown? A maybe better way to show selected options is using MDBSelect?

If you want to use MDBDropdown you can make state, make function to change state and set onClick for your dropdown.

import React from "react";
import { MDBDropdown, MDBDropdownToggle, MDBDropdownMenu, MDBDropdownItem } from "mdbreact";

class LightboxPage extends React.Component {
  state={
    selected:null
  }

  handleSelect = e => this.setState({selected: e.target})

 render(){
  return (
    <MDBDropdown dropup>
      <MDBDropdownToggle caret color="primary">
        Dropup
      </MDBDropdownToggle>
      <MDBDropdownMenu basic>
        <MDBDropdownItem onclick={this.handleSelect}>Action</MDBDropdownItem>
        <MDBDropdownItem onclick={this.handleSelect}>Another Action</MDBDropdownItem>
        <MDBDropdownItem onclick={this.handleSelect}>Something else here</MDBDropdownItem>
        <MDBDropdownItem divider />
        <MDBDropdownItem onclick={this.handleSelect}>Separated link</MDBDropdownItem>
      </MDBDropdownMenu>
    </MDBDropdown>
  );
}};

export default DropdownPage;

Best regards, Konrad.



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.20.0
  • Device: mac
  • Browser: chrome
  • OS: macos
  • Provided sample code: No
  • Provided link: No