Skip to content

Commit

Permalink
pkp/pkp-lib#10624 Add isMultiple prop to Autosuggest component
Browse files Browse the repository at this point in the history
  • Loading branch information
blesildaramirez committed Dec 4, 2024
1 parent 0a82e70 commit 12fdf2e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
18 changes: 16 additions & 2 deletions src/components/Form/fields/Autosuggest.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
class="pkpAutosuggest__input"
v-bind="inputProps"
autocomplete="off"
:disabled="isDisabled || !enableSuggestions"
@change="(event) => handleChange(event)"
@focus="() => handleFocus(true)"
@blur="() => handleFocus(false)"
Expand Down Expand Up @@ -76,7 +77,7 @@
{{ localInputValue }}
</li>
</ComboboxOption>
<template v-if="!isLoading">
<template v-if="!isLoading && enableSuggestions">
<ComboboxOption
v-for="suggestion in suggestions"
:key="suggestion.value"
Expand All @@ -101,7 +102,7 @@
</Combobox>
</template>
<script setup>
import {useSlots, ref, inject} from 'vue';
import {useSlots, ref, inject, computed} from 'vue';
import {
Combobox,
ComboboxInput,
Expand Down Expand Up @@ -147,6 +148,10 @@ const props = defineProps({
type: Boolean,
default: () => false,
},
isMultiple: {
type: Boolean,
default: () => true,
},
inputDescribedByIds: {
type: String,
required: true,
Expand All @@ -172,6 +177,15 @@ const inputProps = {
disabled: props.isDisabled,
};
const enableSuggestions = computed(() => {
if (props.isMultiple) {
return true;
}
// disable multiple selections if only a single item is allowed and an item is already selected."
return !props.currentSelected.length;
});
const emit = defineEmits([
'update:inputValue',
'focus-changed',
Expand Down
3 changes: 1 addition & 2 deletions src/components/Form/fields/FieldRorAutosuggest.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ const {data, isLoading, fetch} = useFetch(url, {
const staticProps = {
id: 'default-autosuggest-autosuggest',
selectedLabel: 'Selected',
isDisabled: false,
deselectLabel: 'Remove {$item}',
inputDescribedByIds: 'default-autosuggest-selected',
inputControlId: 'default-autosuggest-control',
// isMultiple: true,
isMultiple: false,
};
const reactiveProps = reactive({
Expand Down

0 comments on commit 12fdf2e

Please sign in to comment.