+ (this.resultsVisible = true)}"
+ />
+
+
+ ${this.searchResults[0].map(
+ (album) => html`
+
+ `,
+ )}
+ ${this.searchResults[1].map(
+ (artist) => html`
+
+ `,
+ )}
+
+
+ `;
+ }
+
+ private _onQueryChanged(event: Event) {
+ const query = (event.target as HTMLInputElement).value;
+
+ if (this.previousSearchTimeout) {
+ clearTimeout(this.previousSearchTimeout);
+ }
+
+ this.previousSearchTimeout = setTimeout(() => {
+ this.search.run(query);
+ }, 200);
+ }
+
+ private _onKeyDown(event: KeyboardEvent) {
+ if (event.key === "Escape") {
+ this.resultsVisible = false;
+ }
+ }
+
+ private _onMouseDown(event: MouseEvent) {
+ const elementPath = event.composedPath();
+ const popup = this.shadowRoot?.querySelector("sl-popup") as HTMLElement;
+
+ // Close the search results if the user clicks outside of the popup.
+ // `composedPath` returns a list of all elements that the event will pass
+ // through, so if the popup is not in the path, the user clicked outside.
+ if (!elementPath.includes(popup)) {
+ this.resultsVisible = false;
+ }
+ }
+
+ private _onOptionSelected() {
+ this.resultsVisible = false;
+ }
+}
+
+@customElement("command-bar-result")
+class CommandBarResult extends LitElement {
+ @property({ type: String })
+ title = "";
+
+ @property({ type: String })
+ subtitle = "";
+
+ @property({ type: Object })
+ imageSource: Option.Option