facuesr / react-multiselect-listbox

Multiple selection list box component
https://codesandbox.io/s/multi-select-listbox-example-lgvdf
0 stars 2 forks source link

Values not showing #19

Open digitalw opened 2 years ago

digitalw commented 2 years ago

When the list for "value" is non empty, i get 1 item selected, however the list below is empty (not displaying anything). I used the example as a guide.here is my code:

const [selectedTwo, setSelectedTwo] = useState(selected?selected:[]);
.
.
.

  <MultiSelectListBox
        className={"multi-select"}
        overrideStrings={{
          search: "Search...",
          selectAll: "Add All",
          removeAll: "Remove All",
          selectedInfo: "Items selected"
        }}
        sortable={true}
        options={availableDisciplines}
        textField="name"
        valueField="id"
        value={selectedTwo}
        rowHeight={25}
        onSelect={({ item, sortedList }) => {
            add_discipline(item,sortedList)
        }}
        onRemove={({ item }) => {
          remove_disciplie(item)
        }}
        onSelectAll={selectedItems => {
          const selected = [
            ...selectedTwo,
            ...selectedItems.map(item => item.id)
          ];
          setSelectedTwo(selected);
        }}
        onRemoveAll={() => setSelectedTwo([])}
        onSort={({ sortedList }) =>
          setSelectedTwo([...sortedList.map(i => i.id)])
        }
      />

same happens in example code: https://codesandbox.io/s/multi-select-listbox-example-lgvdf?file=/src/App.js