forked from pkp/ui-library
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkp/pkp-lib#10624 Add slots for rendering FieldBaseAutosuggest options
- Loading branch information
1 parent
ac20ff1
commit b1c9e24
Showing
7 changed files
with
295 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<template> | ||
<Combobox | ||
:id="id" | ||
:key="id" | ||
:model-value="null" | ||
class="pkpAutosuggest__autosuggester" | ||
as="div" | ||
> | ||
<ComboboxInput | ||
ref="autosuggestInput" | ||
class="pkpAutosuggest__input" | ||
v-bind="inputProps" | ||
@change="(event) => handleChange(event, emit)" | ||
@focus="() => handleFocus(emit)" | ||
@blur="() => handleBlur(emit)" | ||
/> | ||
<ComboboxOptions | ||
v-if="suggestions.length || (allowCustom && localInputValue?.length)" | ||
class="autosuggest__results-container autosuggest__results" | ||
> | ||
<ComboboxOption | ||
v-if=" | ||
allowCustom && | ||
localInputValue?.length && | ||
!suggestions.includes(localInputValue) | ||
" | ||
v-slot="{active}" | ||
as="template" | ||
> | ||
<li | ||
class="autosuggest__results-item" | ||
:class="active && 'autosuggest__results-item--highlighted'" | ||
> | ||
{{ localInputValue }} | ||
</li> | ||
</ComboboxOption> | ||
<ComboboxOption | ||
v-for="suggestion in suggestions" | ||
:key="suggestion.value" | ||
v-slot="{active}" | ||
:value="suggestion" | ||
as="template" | ||
> | ||
<li | ||
class="autosuggest__results-item flex items-center" | ||
:class="active && 'autosuggest__results-item--highlighted'" | ||
> | ||
<slot v-if="slots['option']" name="option" :suggestion="suggestion" /> | ||
<span v-else>{{ suggestion.label }}</span> | ||
</li> | ||
</ComboboxOption> | ||
</ComboboxOptions> | ||
</Combobox> | ||
</template> | ||
<script setup> | ||
import {useSlots} from 'vue'; | ||
import { | ||
Combobox, | ||
ComboboxInput, | ||
ComboboxOption, | ||
ComboboxOptions, | ||
} from '@headlessui/vue'; | ||
import {useAutosuggest} from '@/composables/useAutosuggest'; | ||
const slots = useSlots(); | ||
defineProps({ | ||
id: { | ||
type: String, | ||
required: true, | ||
}, | ||
inputProps: { | ||
type: Object, | ||
required: true, | ||
}, | ||
suggestions: { | ||
type: Array, | ||
default: () => [], | ||
}, | ||
}); | ||
const emit = defineEmits(['update:inputValue', 'update:isFocused']); | ||
const {allowCustom, localInputValue, handleChange, handleFocus, handleBlur} = | ||
useAutosuggest(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.