diff --git a/src/components/Form/fields/Autosuggest.vue b/src/components/Form/fields/Autosuggest.vue index 72b75907e..36fc5790c 100644 --- a/src/components/Form/fields/Autosuggest.vue +++ b/src/components/Form/fields/Autosuggest.vue @@ -18,7 +18,7 @@ > - {{ deselectLabel.replace('{$item}', item.label) }} + {{ deselectLabel?.replace('{$item}', item.label) }} @@ -31,48 +31,72 @@ @update:model-value="selectSuggestion" >
  • - {{ localInputValue }} + + {{ t('common.loading') }}
  • - - {{ suggestion.label }} + {{ localInputValue }}
  • +
    @@ -86,6 +110,7 @@ import { } from '@headlessui/vue'; import PkpBadge from '@/components/Badge/Badge.vue'; import Icon from '@/components/Icon/Icon.vue'; +import Spinner from '@/components/Spinner/Spinner.vue'; const slots = useSlots(); @@ -94,10 +119,6 @@ const props = defineProps({ type: String, required: true, }, - inputProps: { - type: Object, - required: true, - }, suggestions: { type: Array, default: () => [], @@ -122,36 +143,54 @@ const props = defineProps({ type: String, default: () => '', }, - isFocused: { + isLoading: { type: Boolean, default: () => false, }, + inputDescribedByIds: { + type: String, + required: true, + }, + inputControlId: { + type: String, + required: true, + }, + inputName: { + type: String, + default: () => 'autosuggest', + }, }); +/** + * Props to pass to the input field + */ +const inputProps = { + 'aria-describedby': props.inputDescribedByIds, + class: 'pkpAutosuggest__input', + id: props.inputControlId, + name: props.inputName, + disabled: props.isDisabled, +}; + const emit = defineEmits([ 'update:inputValue', - 'update:isFocused', + 'focus-changed', 'select-suggestion', 'deselect', ]); const allowCustom = inject('allowCustom', false); const localInputValue = ref(''); -const localIsFocused = ref(props.isFocused); +const isFocused = ref(false); function handleChange(event) { localInputValue.value = event.target.value.trim(); emit('update:inputValue', localInputValue.value); } -function handleFocus() { - localIsFocused.value = true; - emit('update:isFocused', localIsFocused.value); -} - -function handleBlur() { - localIsFocused.value = false; - emit('update:isFocused', localIsFocused.value); +function handleFocus(state) { + isFocused.value = state; + emit('focus-changed', state); } function selectSuggestion(suggestion) { @@ -161,4 +200,6 @@ function selectSuggestion(suggestion) { function deselect(item) { emit('deselect', item); } + +defineExpose({handleFocus}); diff --git a/src/components/Form/fields/FieldBaseAutosuggest.stories.js b/src/components/Form/fields/FieldBaseAutosuggest.stories.js index 453ddd119..b5abd178b 100644 --- a/src/components/Form/fields/FieldBaseAutosuggest.stories.js +++ b/src/components/Form/fields/FieldBaseAutosuggest.stories.js @@ -112,12 +112,12 @@ const RORExample = { ); const suggestions = items - .filter((u) => u.fullName.match(regex)) + .filter((u) => u.name.match(regex)) .filter((u) => !this.currentValue.includes(u.id)) .map((u) => { return { value: u.id, - label: u.fullName, + label: u.name, hasSlot: u.ror, }; }); diff --git a/src/components/Form/fields/FieldBaseAutosuggest.vue b/src/components/Form/fields/FieldBaseAutosuggest.vue index 086a1f505..4ac7d32ae 100644 --- a/src/components/Form/fields/FieldBaseAutosuggest.vue +++ b/src/components/Form/fields/FieldBaseAutosuggest.vue @@ -45,7 +45,7 @@ :class="{ 'pkpAutosuggest__inputWrapper--multilingual': isMultilingual && locales.length > 1, - 'pkpAutosuggest__inputWrapper--focus': isFocused, + 'pkpAutosuggest__inputWrapper--focus': inputFocused, }" @click="setFocusToInput" > @@ -83,11 +83,11 @@