Skip to content

Commit

Permalink
Issue #1 - Fixed calculated grouping not working with the "Select All…
Browse files Browse the repository at this point in the history
…" option enabled. (#4)

Issue #2 - Changed how the "Select All" option is unchecked if not all values are selected.
  • Loading branch information
vicky-holcomb authored and sthomas1618 committed Mar 28, 2018
1 parent 0909a14 commit 4cca61a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions src/select/SimpleSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,20 +350,25 @@ class SimpleSelect extends Component {
blur = () => { this.input.blur() }

groupOptions() {
const { groups, groupByKey, options } = this.props
const { allOption, allowSelectAll, groups, groupByKey, options } = this.props

if (groups && groups.length > 0 && groupByKey) {
const orderedOptions = _.orderBy(options, groupByKey)
const parentGroups = []

if (allowSelectAll && !_.includes(parentGroups, allOption)) {
parentGroups.push(allOption)
}

orderedOptions.forEach((option) => {
const group = _.find(groups, [groupByKey, option[groupByKey]])
if (!_.includes(parentGroups, group)) {
group.options = []
parentGroups.push(group)
if (group) {
if (!_.includes(parentGroups, group)) {
group.options = []
parentGroups.push(group)
}
group.options.push(option)
}

group.options.push(option)
})
return parentGroups
}
Expand Down
5 changes: 3 additions & 2 deletions src/select/multiselect/MultiSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ class MultiSelect extends Component {

if (containsVal) {
newValues = option === allOption ? [] :
_.filter(valueObjs, val => (allowSelectAll ?
val[valKey] !== option[valKey] && val !== allOption : val[valKey] !== option[valKey]))
_.filter(valueObjs, val => (
allowSelectAll ? val[valKey] !== option[valKey] && val[valueKey] !== allOption[valueKey]
: val[valKey] !== option[valKey]))
} else if (isGroup) {
newValues = [...valueObjs, ...option.options]
} else if (option === allOption) {
Expand Down
3 changes: 2 additions & 1 deletion stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ stories.add('with MultiSelect and pre-formed grouping', () => (
/>
))

stories.add('with MultiSelect and calculated grouping', () => (
stories.add('with MultiSelect and calculated grouping and select all', () => (
<BasicMultiSelect
options={terms}
labelKey="value"
Expand All @@ -150,6 +150,7 @@ stories.add('with MultiSelect and calculated grouping', () => (
clearable={boolean('Clearable', false)}
placeholder={text('Placeholder', 'Select value...')}
openOnClick={boolean('Open On Click', true)}
allowSelectAll={boolean('Allow Select All', true)}
/>
))

Expand Down

0 comments on commit 4cca61a

Please sign in to comment.