Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ The `<SelectableGroup />` component accepts a few optional props:

- `duringSelection` (Function) Callback fired rapidly during selection (while the selector is being dragged). Passes an array containing selectable items currently under the selector to the callback function.
- `onSelectionFinish` (Function) Callback.
- `onUnselectedFinish` (Function) Callback. Called at the same time as `onSelectionFinish`, this returns all the unselected values.
- `onSelectionClear` (Function) Callback.
- `onSelectedItemUnmount` (Function) Callback.
- `enableDeselect` (Boolean) Enables deselect with selectbox.
Expand Down
14 changes: 14 additions & 0 deletions src/SelectableGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export type TSelectableGroupProps = {
selectionModeClass?: string
// Event that will fire when items are selected. Passes an array of keys.
onSelectionFinish?: Function
onUnselectedFinish?: (items: TSelectableItem[]) => void
onSelectionClear?: Function
onSelectedItemUnmount?: Function
enableDeselect?: boolean
Expand Down Expand Up @@ -168,6 +169,15 @@ export class SelectableGroup extends Component<TSelectableGroupProps> {
scrollLeft: 0,
}

onUnselectedFinish() {
if (!this.props.onUnselectedFinish) return
const a = this.registry
const b = this.selectedItems
const unselected = new Set(
[...a].filter(x => !b.has(x)));
this.props.onUnselectedFinish([...unselected])
}

componentDidMount() {
if (this.props.scrollContainer) {
this.scrollContainer = document.querySelector(this.props.scrollContainer)
Expand Down Expand Up @@ -459,6 +469,7 @@ export class SelectableGroup extends Component<TSelectableGroupProps> {

this.setState({ selectionMode: false })
this.props.onSelectionFinish!([...this.selectedItems])
this.onUnselectedFinish()
this.props.onSelectionClear!()
}

Expand All @@ -474,6 +485,7 @@ export class SelectableGroup extends Component<TSelectableGroupProps> {

this.setState({ selectionMode: true })
this.props.onSelectionFinish!([...this.selectedItems])
this.onUnselectedFinish()
}

isInIgnoreList(target: HTMLElement | null) {
Expand Down Expand Up @@ -619,6 +631,7 @@ export class SelectableGroup extends Component<TSelectableGroupProps> {
height: 0,
})
this.props.onSelectionFinish!([...this.selectedItems])
this.onUnselectedFinish()
}

this.toggleSelectionMode()
Expand Down Expand Up @@ -695,6 +708,7 @@ export class SelectableGroup extends Component<TSelectableGroupProps> {
)

onSelectionFinish!([...this.selectedItems], this.clickedItem)
this.onUnselectedFinish()

if (evt.which === 1) {
this.preventEvent(evt.target, 'click')
Expand Down