In a react Multiselect dropdown I would like to display name and email along with the checkbox in the same level

2.1k Views Asked by At

In a react Multiselect dropdown I would like to display name and email along with the checkbox in the same level (as per the screenshot attached ) is that possible using multiselect-react-dropdown ? I have tried below, but it is still the name only. How can we insert email along with name option may be in fade color, any advise ?

Added the codesandbox test link: https://codesandbox.io/s/stoic-cartwright-9tb3i?file=/src/App.js:395-419

import Multiselect from 'multiselect-react-dropdown';

    const options = [
        { key: 'Dan', email: '[email protected]', id: 1},
        { key: 'Crots', email: '[email protected]', id: 2},
        { key: 'Sum', email: '[email protected]', id: 3},
        { key: 'Tim', email: '[email protected]', id: 4}
      ];

   const [selectedOption, setSelectedOption] = useState([]);   
   const handleTypeSelect = (e) => {
        const copy = [...selectedOption];
        copy.push(e);
        setSelectedOption(copy);
    };

    <div className="nomineeSelectBox">
             <div id="dialog2" className="triangle_down1"/>
                <div className="arrowdown">
                    <Multiselect
                        onSelect={handleTypeSelect}
                        options={selectedOption.length + 1 === maxOptions ? [] : options}
                        displayValue="key"
                        showCheckbox={true}
                        emptyRecordMsg={"Maximum nominees selected !"}
                    />
    
                </div>
            </div>

enter image description here

1

There are 1 best solutions below

5
The KNVB On BEST ANSWER

You may try to add the following code:

options.forEach(option=>{
   option.displayValue=option.key+"\t"+option.email;
})

Before the return statement. And then change the following code:

<Multiselect
        onSelect={handleTypeSelect}
        onRemove={handleTypeRemove}
        options={selectedOption.length + 1 === maxOptions ? [] : options}
        displayValue="key"
        showCheckbox={true}
        emptyRecordMsg={"Maximum nominees selected !"}
      />

to

<Multiselect
        onSelect={handleTypeSelect}
        onRemove={handleTypeRemove}
        options={selectedOption.length + 1 === maxOptions ? [] : options}
        displayValue="displayValue"
        showCheckbox={true}
        emptyRecordMsg={"Maximum nominees selected !"}
      />