Skip to content

Commit

Permalink
Fixed #2525 - empty slot for Autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Jan 9, 2023
1 parent 0ae83cd commit 8bc2c63
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
8 changes: 6 additions & 2 deletions api-generator/components/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,15 @@ const AutoCompleteSlots = [
},
{
name: 'content',
description: 'Custom content for the virtual scroller'
description: 'Custom content for the virtual scroller.'
},
{
name: 'loader',
description: 'Custom content for the virtual scroller loader items'
description: 'Custom content for the virtual scroller loader items.'
},
{
name: 'empty',
description: 'Custom empty template when there is no data to display.'
}
];

Expand Down
4 changes: 4 additions & 0 deletions components/autocomplete/AutoComplete.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ export interface AutoCompleteSlots {
*/
options: any[];
}) => VNode[];
/**
* Custom empty template when there is no data to display.
*/
empty: () => VNode[];
}

export declare type AutoCompleteEmits = {
Expand Down
5 changes: 4 additions & 1 deletion components/autocomplete/AutoComplete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@
<!--TODO: Deprecated since v3.16.0-->
</li>
</template>
<li v-if="!items || (items && items.length === 0)" class="p-autocomplete-empty-message" role="option">
<slot name="empty">{{ searchResultMessageText }}</slot>
</li>
</ul>
</template>
<template v-if="$slots.loader" v-slot:loader="{ options }">
Expand Down Expand Up @@ -323,7 +326,7 @@ export default {
watch: {
suggestions() {
if (this.searching) {
ObjectUtils.isNotEmpty(this.suggestions) ? this.show() : this.hide();
ObjectUtils.isNotEmpty(this.suggestions) ? this.show() : !!this.$slots.empty ? this.show() : this.hide();
this.focusedOptionIndex = this.overlayVisible && this.autoOptionFocus ? this.findFirstFocusedOptionIndex() : -1;
this.searching = false;
}
Expand Down
8 changes: 8 additions & 0 deletions pages/autocomplete/AutoCompleteDoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,10 @@ export default {
<td>loader</td>
<td>options: Options of the loader items for virtualscroller</td>
</tr>
<tr>
<td>empty</td>
<td>-</td>
</tr>
</tbody>
</table>
</div>
Expand Down Expand Up @@ -605,6 +609,10 @@ export default {
<td>p-autocomplete-token-label</td>
<td>Label of a selected item in multiple mode.</td>
</tr>
<tr>
<td>p-autocomplete-empty-message</td>
<td>Container element when there is no suggestion to display.</td>
</tr>
<tr>
<td>p-overlay-open</td>
<td>Container element when overlay is visible.</td>
Expand Down

0 comments on commit 8bc2c63

Please sign in to comment.