Skip to content

Commit

Permalink
Fixed #1288 - MultiSelect selectionLimit showToggleAll
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed May 21, 2021
1 parent 0679d9c commit b23d409
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/components/multiselect/MultiSelect.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ declare class MultiSelect extends Vue {
appendTo?: string;
emptyFilterMessage?: string;
display?: string;
selectionLimit?: number;
showToggleAll?: boolean;
$emit(eventName: 'input', value: any): this;
$emit(eventName: 'change', e: {originalEvent: Event, value: any}): this;
$emit(eventName: 'before-show'): this;
Expand Down
19 changes: 17 additions & 2 deletions src/components/multiselect/MultiSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
</div>
<transition name="p-connected-overlay" @enter="onOverlayEnter" @leave="onOverlayLeave">
<div ref="overlay" class="p-multiselect-panel p-component" v-if="overlayVisible">
<div class="p-multiselect-header">
<div class="p-checkbox p-component" @click="onToggleAll" role="checkbox" :aria-checked="allSelected">
<div class="p-multiselect-header" v-if="(showToggleAll && selectionLimit == null) || filter">
<div class="p-checkbox p-component" v-if="showToggleAll && selectionLimit == null" @click="onToggleAll" role="checkbox" :aria-checked="allSelected">
<div class="p-hidden-accessible">
<input type="checkbox" readonly @focus="onHeaderCheckboxFocus" @blur="onHeaderCheckboxBlur">
</div>
Expand Down Expand Up @@ -100,6 +100,14 @@ export default {
display: {
type: String,
default: 'comma'
},
selectionLimit: {
type: Number,
default: null
},
showToggleAll: {
type: Boolean,
default: true
}
},
data() {
Expand Down Expand Up @@ -134,6 +142,9 @@ export default {
return this.dataKey ? ObjectUtils.resolveFieldData(option, this.dataKey) : this.getOptionLabel(option);
},
isOptionDisabled(option) {
if (this.maxSelectionLimitReached && !this.isSelected(option)) {
return true;
}
return this.optionDisabled ? ObjectUtils.resolveFieldData(option, this.optionDisabled) : false;
},
isSelected(option) {
Expand Down Expand Up @@ -483,6 +494,9 @@ export default {
},
equalityKey() {
return this.optionValue ? null : this.dataKey;
},
maxSelectionLimitReached() {
return this.selectionLimit && (this.value && this.value.length === this.selectionLimit);
}
},
directives: {
Expand Down Expand Up @@ -592,6 +606,7 @@ export default {
flex-shrink: 0;
overflow: hidden;
position: relative;
margin-left: auto;
}
.p-fluid .p-multiselect {
Expand Down
12 changes: 12 additions & 0 deletions src/views/multiselect/MultiSelectDoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,18 @@ data() {
<td>string</td>
<td>comma</td>
<td>Defines how the selected items are displayed, valid values are "comma" and "chip".</td>
</tr>
<tr>
<td>selectionLimit</td>
<td>number</td>
<td>null</td>
<td>Maximum number of selectable items.</td>
</tr>
<tr>
<td>showToggleAll</td>
<td>boolean</td>
<td>true</td>
<td>Whether to show the header checkbox to toggle the selection of all items at once.</td>
</tr>
</tbody>
</table>
Expand Down

0 comments on commit b23d409

Please sign in to comment.