Skip to content

Commit

Permalink
pkp/pkp-lib#10624 Convert allowCustom to a prop instead of provide/re…
Browse files Browse the repository at this point in the history
…ject to Autosuggest component
  • Loading branch information
blesildaramirez committed Jan 9, 2025
1 parent 7a3a2de commit eb1ff4e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/components/Form/fields/Autosuggest.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
</Combobox>
</template>
<script setup>
import {useSlots, ref, inject, computed} from 'vue';
import {useSlots, ref, computed} from 'vue';
import {
Combobox,
ComboboxInput,
Expand Down Expand Up @@ -157,6 +157,11 @@ const props = defineProps({
type: Boolean,
default: () => true,
},
/** If custom items can be selected */
allowCustom: {
type: Boolean,
default: () => false,
},
/** Field input id, usually used to connect with FormFieldLabel */
inputId: {type: String, required: false, default: null},
/** aria-describedby ids */
Expand Down Expand Up @@ -189,7 +194,6 @@ const emit = defineEmits([
'deselect',
]);
const allowCustom = inject('allowCustom', false);
const localInputValue = ref('');
const isFocused = ref(false);
Expand Down
6 changes: 6 additions & 0 deletions src/components/Form/fields/FieldBaseAutosuggest.vue
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ export default {
type: Boolean,
default: () => true,
},
/** If custom items can be selected */
allowCustom: {
type: Boolean,
default: () => false,
},
},
data() {
return {
Expand Down Expand Up @@ -257,6 +262,7 @@ export default {
isDisabled: this.isDisabled,
inputId: this.controlId,
describedBy: this.describedByIds,
allowCustom: this.allowCustom,
};
},
},
Expand Down
9 changes: 6 additions & 3 deletions src/components/Form/fields/FieldControlledVocab.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<script>
import {provide} from 'vue';
import FieldBaseAutosuggest from './FieldBaseAutosuggest.vue';
import debounce from 'debounce';
export default {
name: 'FieldControlledVocab',
extends: FieldBaseAutosuggest,
setup() {
provide('allowCustom', true);
props: {
/** An array of options to suggest. */
allowCustom: {
type: Boolean,
default: true,
},
},
data() {
return {
Expand Down
5 changes: 2 additions & 3 deletions src/components/Form/fields/FieldRorAutosuggest.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
</template>

<script setup>
import {ref, watch, computed, provide} from 'vue';
import {ref, watch, computed} from 'vue';
import Autosuggest from './Autosuggest.vue';
import Icon from '@/components/Icon/Icon.vue';
import {useFetch} from '@/composables/useFetch';
Expand All @@ -70,8 +70,6 @@ const queryParams = computed(() => ({
query: inputValue.value,
}));
provide('allowCustom', true);
const autosuggestContainerId = generateId();
const {
Expand All @@ -87,6 +85,7 @@ const staticProps = {
selectedLabel: 'Selected',
isMultiple: false,
describedBy: autosuggestContainerId,
allowCustom: true,
};
const autoSuggestProps = computed(() => ({
Expand Down

0 comments on commit eb1ff4e

Please sign in to comment.