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/#6216 MultiSelect - SelectionLimit issue #6218

Merged
merged 7 commits into from
Apr 13, 2024
Merged
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
20 changes: 17 additions & 3 deletions components/lib/multiselect/MultiSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,11 @@ export const MultiSelect = React.memo(
}
}

// make sure not to exceed the selection limit
if (props.selectionLimit && value && value.length) {
value = value.slice(0, props.selectionLimit);
}

updateModel(event.originalEvent, value, value);
}
};
Expand Down Expand Up @@ -681,11 +686,20 @@ export const MultiSelect = React.memo(
};

const isOptionDisabled = (option) => {
if (props.optionDisabled) {
return ObjectUtils.isFunction(props.optionDisabled) ? props.optionDisabled(option) : ObjectUtils.resolveFieldData(option, props.optionDisabled);
// disable if we have hit our selection limit
if (!allowOptionSelect() && !isSelected(option)) {
return true;
}

// check if custom optionDisabled function is being used
const { optionDisabled } = props;

if (optionDisabled) {
return ObjectUtils.isFunction(optionDisabled) ? optionDisabled(option) : ObjectUtils.resolveFieldData(option, optionDisabled);
}

return option && option.disabled !== undefined ? option.disabled : false;
// fallback to the option itself disabled value
return option && (option.disabled ?? false);
};

const isOptionValueUsed = (option) => {
Expand Down
Loading