Skip to content

Commit eb1ff4e

Browse files
pkp/pkp-lib#10624 Convert allowCustom to a prop instead of provide/reject to Autosuggest component
1 parent 7a3a2de commit eb1ff4e

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

src/components/Form/fields/Autosuggest.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
</Combobox>
104104
</template>
105105
<script setup>
106-
import {useSlots, ref, inject, computed} from 'vue';
106+
import {useSlots, ref, computed} from 'vue';
107107
import {
108108
Combobox,
109109
ComboboxInput,
@@ -157,6 +157,11 @@ const props = defineProps({
157157
type: Boolean,
158158
default: () => true,
159159
},
160+
/** If custom items can be selected */
161+
allowCustom: {
162+
type: Boolean,
163+
default: () => false,
164+
},
160165
/** Field input id, usually used to connect with FormFieldLabel */
161166
inputId: {type: String, required: false, default: null},
162167
/** aria-describedby ids */
@@ -189,7 +194,6 @@ const emit = defineEmits([
189194
'deselect',
190195
]);
191196
192-
const allowCustom = inject('allowCustom', false);
193197
const localInputValue = ref('');
194198
const isFocused = ref(false);
195199

src/components/Form/fields/FieldBaseAutosuggest.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ export default {
189189
type: Boolean,
190190
default: () => true,
191191
},
192+
/** If custom items can be selected */
193+
allowCustom: {
194+
type: Boolean,
195+
default: () => false,
196+
},
192197
},
193198
data() {
194199
return {
@@ -257,6 +262,7 @@ export default {
257262
isDisabled: this.isDisabled,
258263
inputId: this.controlId,
259264
describedBy: this.describedByIds,
265+
allowCustom: this.allowCustom,
260266
};
261267
},
262268
},

src/components/Form/fields/FieldControlledVocab.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
<script>
2-
import {provide} from 'vue';
32
import FieldBaseAutosuggest from './FieldBaseAutosuggest.vue';
43
import debounce from 'debounce';
54
65
export default {
76
name: 'FieldControlledVocab',
87
extends: FieldBaseAutosuggest,
9-
setup() {
10-
provide('allowCustom', true);
8+
props: {
9+
/** An array of options to suggest. */
10+
allowCustom: {
11+
type: Boolean,
12+
default: true,
13+
},
1114
},
1215
data() {
1316
return {

src/components/Form/fields/FieldRorAutosuggest.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
</template>
5555

5656
<script setup>
57-
import {ref, watch, computed, provide} from 'vue';
57+
import {ref, watch, computed} from 'vue';
5858
import Autosuggest from './Autosuggest.vue';
5959
import Icon from '@/components/Icon/Icon.vue';
6060
import {useFetch} from '@/composables/useFetch';
@@ -70,8 +70,6 @@ const queryParams = computed(() => ({
7070
query: inputValue.value,
7171
}));
7272
73-
provide('allowCustom', true);
74-
7573
const autosuggestContainerId = generateId();
7674
7775
const {
@@ -87,6 +85,7 @@ const staticProps = {
8785
selectedLabel: 'Selected',
8886
isMultiple: false,
8987
describedBy: autosuggestContainerId,
88+
allowCustom: true,
9089
};
9190
9291
const autoSuggestProps = computed(() => ({

0 commit comments

Comments
 (0)