wenzhixin/multiple-select

optgroup representation in .msdrop not toggled correct

IZSkiSurfer opened this issue · 0 comments

In

this.$drop.find(`input[data-key=${row._key}]`).prop('checked', row.selected)
we need to also search for span[data-key=${row._key}] to toggle the optgroup representation as well.

And in

row.selected = !this.options.single && selectedCount && selectedCount ===
we must convert selectedCount to boolean.

so replace
row.selected = !this.options.single && selectedCount && selectedCount ===
with
row.selected = !this.options.single && !!selectedCount && selectedCount ===

Atm row.selected will be evalutated to 0 if selectedCount is 0 and if we use this value in

this.$drop.find(`input[data-key=${row._key}]`).prop('checked', row.selected)
.closest('li').toggleClass('selected', row.selected)
to toggle the class (and change prop) the class "selected" will be toggled and not removed (see https://api.jquery.com/toggleclass/#toggleClass-className-state which clearly states that the state must be boolean - not truthy/falsy)