From ccfc944d6e1982c8d9d2f61770d6ec6180313260 Mon Sep 17 00:00:00 2001 From: charithAmila Date: Sat, 23 Mar 2024 23:32:51 -0400 Subject: [PATCH 1/5] fix: 6216 disabled option with selectionLimit --- components/lib/multiselect/MultiSelect.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/lib/multiselect/MultiSelect.js b/components/lib/multiselect/MultiSelect.js index e2b1250305..683c70d0da 100644 --- a/components/lib/multiselect/MultiSelect.js +++ b/components/lib/multiselect/MultiSelect.js @@ -653,6 +653,10 @@ export const MultiSelect = React.memo( return ObjectUtils.isFunction(props.optionDisabled) ? props.optionDisabled(option) : ObjectUtils.resolveFieldData(option, props.optionDisabled); } + if (props.selectionLimit && props.value && props.value.length >= props.selectionLimit && !isSelected(option)) { + return true; + } + return option && option['disabled'] !== undefined ? option['disabled'] : false; }; From 58b2ff86bab3f86b43967696cb15ba16ede8bf5b Mon Sep 17 00:00:00 2001 From: charithAmila Date: Sat, 23 Mar 2024 23:41:31 -0400 Subject: [PATCH 2/5] fix: 6216 handle selectionLimit select all --- components/lib/multiselect/MultiSelect.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/lib/multiselect/MultiSelect.js b/components/lib/multiselect/MultiSelect.js index 1f3f154767..953981d677 100644 --- a/components/lib/multiselect/MultiSelect.js +++ b/components/lib/multiselect/MultiSelect.js @@ -400,6 +400,10 @@ export const MultiSelect = React.memo( } } + if (props.selectionLimit && value && value.length) { + value = value.slice(0, props.selectionLimit); + } + updateModel(event.originalEvent, value, value); } }; From 9fbc14e45d26b83e720b0f1b5a2c5bcf0a13d9c1 Mon Sep 17 00:00:00 2001 From: Melloware Date: Sat, 13 Apr 2024 07:47:48 -0400 Subject: [PATCH 3/5] Update MultiSelect.js --- components/lib/multiselect/MultiSelect.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/components/lib/multiselect/MultiSelect.js b/components/lib/multiselect/MultiSelect.js index fd7a0f97e5..21f5ad4427 100644 --- a/components/lib/multiselect/MultiSelect.js +++ b/components/lib/multiselect/MultiSelect.js @@ -422,6 +422,7 @@ 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); } @@ -685,15 +686,19 @@ export const MultiSelect = React.memo( }; const isOptionDisabled = (option) => { - if (props.optionDisabled) { - return ObjectUtils.isFunction(props.optionDisabled) ? props.optionDisabled(option) : ObjectUtils.resolveFieldData(option, props.optionDisabled); + // check if custom optionDisabled function is being used + const { optionDisabled } = props; + if (optionDisabled) { + return ObjectUtils.isFunction(optionDisabled) ? optionDisabled(option) : ObjectUtils.resolveFieldData(option, optionDisabled); } - if (props.selectionLimit && props.value && props.value.length >= props.selectionLimit && !isSelected(option)) { + // disable if we have hit our selection limit + if (!allowOptionSelect() && !isSelected(option)) { return true; } - - return option && option.disabled !== undefined ? option.disabled : false; + + // fallback to the option itself disabled value + return option && (option.disabled ?? false); }; const isOptionValueUsed = (option) => { From dd1115a416998ec1ab5f70e735eca2bcdbc849eb Mon Sep 17 00:00:00 2001 From: Melloware Date: Sat, 13 Apr 2024 07:51:28 -0400 Subject: [PATCH 4/5] Update MultiSelect.js --- components/lib/multiselect/MultiSelect.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/components/lib/multiselect/MultiSelect.js b/components/lib/multiselect/MultiSelect.js index 21f5ad4427..e0e85fa294 100644 --- a/components/lib/multiselect/MultiSelect.js +++ b/components/lib/multiselect/MultiSelect.js @@ -686,17 +686,17 @@ export const MultiSelect = React.memo( }; const isOptionDisabled = (option) => { + // 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); } - // disable if we have hit our selection limit - if (!allowOptionSelect() && !isSelected(option)) { - return true; - } - // fallback to the option itself disabled value return option && (option.disabled ?? false); }; From c688fa66f1f947686b36a977aa63f620650e403d Mon Sep 17 00:00:00 2001 From: Melloware Date: Sat, 13 Apr 2024 08:13:20 -0400 Subject: [PATCH 5/5] Update MultiSelect.js --- components/lib/multiselect/MultiSelect.js | 1 + 1 file changed, 1 insertion(+) diff --git a/components/lib/multiselect/MultiSelect.js b/components/lib/multiselect/MultiSelect.js index e0e85fa294..1daa91423a 100644 --- a/components/lib/multiselect/MultiSelect.js +++ b/components/lib/multiselect/MultiSelect.js @@ -693,6 +693,7 @@ export const MultiSelect = React.memo( // check if custom optionDisabled function is being used const { optionDisabled } = props; + if (optionDisabled) { return ObjectUtils.isFunction(optionDisabled) ? optionDisabled(option) : ObjectUtils.resolveFieldData(option, optionDisabled); }