/** * Search Bar Component * Search input with icon */ class SearchBar extends HTMLElement { constructor() { super(); this.attachShadow({ mode: "open" }); } connectedCallback() { this.render(); this.addEventListeners(); } addEventListeners() { const input = this.shadowRoot.querySelector(".search-input"); const form = this.shadowRoot.querySelector(".search-form"); form.addEventListener("submit", (e) => { e.preventDefault(); this.dispatchEvent( new CustomEvent("search", { detail: { query: input.value }, bubbles: true, composed: true, }) ); }); input.addEventListener("input", (e) => { this.dispatchEvent( new CustomEvent("search-input", { detail: { query: e.target.value }, bubbles: true, composed: true, }) ); }); } render() { this.shadowRoot.innerHTML = ` `; } } customElements.define("search-bar", SearchBar);