Skip to content

Commit

Permalink
Fix #5247: Multiselect onRemove event (#5248)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Nov 6, 2023
1 parent bf9b11c commit 0091ad3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions components/lib/multiselect/MultiSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,13 @@ export const MultiSelect = React.memo(
const removeChip = (event, item) => {
const value = props.value.filter((val) => !ObjectUtils.equals(val, item, equalityKey));

if (props.onRemove) {
props.onRemove({
originalEvent: event,
value
});
}

updateModel(event, value, item);
};

Expand Down
1 change: 1 addition & 0 deletions components/lib/multiselect/MultiSelectBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ export const MultiSelectBase = ComponentBase.extend({
onFilter: null,
onFocus: null,
onHide: null,
onRemove: null,
onSelectAll: null,
onShow: null,
optionDisabled: null,
Expand Down
20 changes: 20 additions & 0 deletions components/lib/multiselect/multiselect.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,21 @@ interface MultiSelectChangeEvent {
target: MultiSelectChangeTargetOptions;
}

/**
* Custom remove event when chip is removed.
* @event
*/
interface MultiSelectRemoveEvent {
/**
* Browser event
*/
originalEvent: React.SyntheticEvent;
/**
* Removed item value
*/
value: any;
}

/**
* Custom filter event.
* @see {@link MultiSelectProps.onFilter}
Expand Down Expand Up @@ -709,6 +724,11 @@ export interface MultiSelectProps extends Omit<React.DetailedHTMLProps<React.Inp
* Callback to invoke when overlay panel becomes hidden.
*/
onHide?(): void;
/**
* Callback to invoke when a chip is removed.
* @param {MultiSelectRemoveEvent} event - Custom remove event
*/
onRemove?(event: MultiSelectRemoveEvent): void;
/**
* Callback to invoke when all data is selected.
* @param {MultiSelectAllEvent} event - Custom select event.
Expand Down

0 comments on commit 0091ad3

Please sign in to comment.