Skip to content

Commit a717eb7

Browse files
committed
Add named slot for empty list state
1 parent f3329ac commit a717eb7

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/labs/ia-combo-box/ia-combo-box.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,8 @@ export class IAComboBox extends LitElement {
469469
*/
470470
private get optionTemplates(): TemplateResult[] {
471471
// If there are no options matching the filter, just show a message saying as much.
472-
if (this.filteredOptions.length === 0) {
473-
return [this.noOptionsMessageTemplate];
472+
if (this.filteredOptions.length === 0 && this.maxAutocompleteEntries > 0) {
473+
return [this.emptyOptionsTemplate];
474474
}
475475

476476
// Otherwise build a list item for each filtered option
@@ -500,9 +500,14 @@ export class IAComboBox extends LitElement {
500500

501501
/**
502502
* Info message shown in the listbox when no options match the entered text.
503+
* Renders within an `empty-options` named slot so that its content can be customized.
503504
*/
504-
private get noOptionsMessageTemplate(): TemplateResult {
505-
return html`<li id="no-options-msg">${msg('No matching options')}</li>`;
505+
private get emptyOptionsTemplate(): TemplateResult {
506+
return html`
507+
<li id="empty-options" part="empty-options">
508+
<slot name="empty-options">${msg('No matching options')}</slot>
509+
</li>
510+
`;
506511
}
507512

508513
//
@@ -1118,7 +1123,7 @@ export class IAComboBox extends LitElement {
11181123
opacity: 1;
11191124
}
11201125
1121-
#no-options-msg {
1126+
#empty-options {
11221127
padding: 5px;
11231128
color: #606060;
11241129
font-style: italic;

0 commit comments

Comments
 (0)