Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #5247: Multiselect onRemove event #5248

Merged
merged 1 commit into from
Nov 6, 2023
Merged
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
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
Loading