Render multiple lines for each item dropdown in React

react dropdown example
react-dropdown-select
react dropdown with images
react-select multiline

How can I render multiple lines for each item in the dropdown. Ex: I need to display address1 in first-line and city, the state in second line for each item in the dropdown. \n and \br doesn't work. Any help would be appreciated.

React.render(
    <Dropdown label="Dropdown Label">
      <DropdownItem label="1 main street \n  sacramento, california" value="Number 1" />
      <DropdownItem label="2 main street \n  stockton, california" value="2" />
    </Dropdown>,
  document.getElementById('app')
);

You can use JavaScript's Map function. You can have city names as an array and have their position index as the key and name of the city as value. More information can be found in React documentation and an example can be seen here. Example below:

  function Filter(props){
  const Items = ['All', 'Car', 'Truck', 'Convetible'];
  const MappingItems = Items.map((Item) => <option>{Item}</option> );
  return (
    <div style={divStyle}>
      New Only <input type="checkbox" /><br /><br />
      Select Type <select>
        {MappingItems}
      </select>
    </div>
  )
}

ReactDOM.render(
  <Filter />,
  document.getElementById('root')
);

Hope this helps!

React and Ionic Select Multiline select Example, React Select scroller style demo supporting long text rendered in multiple rows. With smooth scrolling and native look & feel. For React. A convenience component for simple or general use dropdowns. Renders a Button toggle and all children are passed directly to the default Dropdown.Menu.. All unknown props are passed through to the Dropdown component.

If you have a dropdown list like the following:

<select>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select> 

In most cases, this dropdown list will be dynamic, Its better to keep it in an array and then use javascript higher order function to map over it

const optionsList = [
   {
      name: 'Volvo',
      value: 'volvo',
   },
   {
     name: 'Saab',
     value: 'saab',
   },
  // And the no of drop down items could be dynamic
];

// Now in your render method
React.render(
    <select onChange={onChangeFunction}>
    {optionsList.map(option => (
      <option value={option.value} key={option.name}>{option.name}</option>
    ))}
    </select>,
  document.getElementById('app')
);

// In this way your dropdown will appear as a dropdown list on the newline without using breaks or newlines

P.S. Dont forget to miss the key while mapping options. React will thank you ;)

And now you have all the flexiblity to make this select your custom component by giving it styles of your choice.

How to Use a Multiline Text Area in ReactJS, To make a textarea in React, use the input tag. handleChange(event) { console​.log(event.target.value) } render() <textarea> is the official tag in HTML5 to define a multi-line text input A great advantages of using <textarea> is that it provides multi-line input values so that all values can be completely  And that’s it, you’ve mastered the art of iterating & rendering loops in React! If you’re interested in learning more, this post from Jason Lee is fantastic and worth a read. What's Next. To really dig deep into React, check out this full day workshop from Kent C Dodds on the fundamentals of react.

here you go , as per your requirement:

import React from "react";
import ReactDOM from "react-dom";
const DropdownItem = props => {
  return (
    <option label={props.value} value={props.label}>
      {props.value}
    </option>
  );
};

class Dropdown extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      value: ""
    };
  }

  handleChange = e => {
    this.setState({ value: String(e.target.value) });
  };
  render() {
    return (
      <>
        <select value={this.state.value} onChange={this.handleChange}>
          {this.props.children.map(DropdownItem => {
            return DropdownItem;
          })}
        </select>
        <div>
          {this.state.value.split("\\n").map((item, i) => {
            return <p key={i}>{item}</p>;
          })}
        </div>
      </>
    );
  }
}

ReactDOM.render(
  <Dropdown label="Dropdown Label">
    <DropdownItem
      label="1 main street \n sacramento, california"
      value="Number 1"
    />
    <DropdownItem
      label="2 main street \n stockton, california"
      value="Number 2"
    />
  </Dropdown>,
  document.getElementById("app")
);

https://codesandbox.io/s/react-hooks-counter-demo-vjocy

Multi-Column ComboBox Drop Down | Input, If the items are complex objects, you may want to render a single item per line, but with additional detail, as in a table or grid. You can accomplish this with the  I have two dropdowns being passed in as props to components. I can control both with seperate states but I think this can all be done with one state? Header import React from 'react'; import Dark

Pro MERN Stack: Full Stack Web App Development with Mongo, , Full Stack Web App Development with Mongo, Express, React, and Node Vasan We don't want to break either the effort inputs or the buttons into multiple lines even 3 cells of 6 columns each, totaling 18 columns, can fit a row of 12 columns. component class of the actual element that is rendered, such as input​, select,  It seems the old answer about returning an array no longer applies (maybe since React ~0.9, as @dogmatic69 wrote in a comment).. The docs say you need to return a single node:

Dropdown, Multiple Search Selection. A selection dropdown can allow multiple search selections. A "multiple" dropdown can render customized label for selected items. After a React component does mount, it will be listening for any React props or state that has changed. Once it detects something has changed, it will, by default, re-render the entire React component and it’s child components. Is it bad to re-render multiple React components? Yes, and no. In theory, having every component re-render can be

Multiple checkbox handling by React JS - Tariqul Islam, Today i build some example about multiple checkbox with React JS. After that create react applcation by this command from command line fruite items which is using for generate checkbox group. render is the function which is Pass All the properties from App component to CheckBox component by  React/ReactJS: Dynamic Select/Option. In the first section of this tutorial, you will learn how to add options dynamically to a select/option dropdown in React/ReactJS with array values and with object literal properties.

Comments
  • Is this some UI library or just custom Components?
  • This is custom component
  • Hi, My design needs to have drop down and when they click the dropdown it should expand in this format
  • My design needs to have drop down and when they click the dropdown it should expand in this format 233 (dropdown) 233 1 main street (list view) sacramento 234 2 main street (list view) stockton
  • sorry i don't understand format, do you have a image (whats list view in this) ?
  • Hi, Does it display the drop down list in this format. It needs to show two drop down values in the format 1 main street sacramento, california 2 main street Stockton, california
  • Go to the link below and there you will find how I have displayed the names of different types of vehicles using the map method. Hope it helps. Link: codepen.io/savi_dulai/pen/gOORzxX
  • My design needs to have drop down and when they click the dropdown it should expand in this format 233 (dropdown) 233 1 main street (list view) sacramento 234 2 main street (list view) stockton
  • My design needs to have drop down and when they click the dropdown it should expand in this format 233 (dropdown) 233 1 main street (list view) sacramento 234 2 main street (list view) stockton
  • My design needs to have drop down and when they click the dropdown it should expand in this format 233 (dropdown) 233 1 main street (list view) sacramento 234 2 main street (list view) stockton