advanced forms
Tailwind CSS Combo Box
The ComboBox JavaScript plugin improves user experience by dynamically suggesting options as users type into an input field.
The code snippet outlines a ComboBox with specific data attributes to manage its behavior. The outer <div> with data-combo-box signifies that this section is the main ComboBox component. Within it, an <input> field with data-combo-box-input allows users to type text to get suggestions.
An accompanying icon element with data-combo-box-toggle acts as a button to open or close the dropdown menu, indicating it has a dropdown function. The dropdown menu itself is an <div> with data-combo-box-output, which contains several suggestion items. These individual suggestion items are <div> elements with data-combo-box-output-item. Each item has a data-combo-box-search-text attribute that holds the text displayed for that option in the dropdown.
Below example shows basic use of combo-box.
<div class="relative max-w-sm" data-combo-box="">
<div class="relative">
<input class="input" type="text" value="India" role="combobox" aria-expanded="false" data-combo-box-input="" aria-label="Default combobox" />
<span class="icon-[tabler--caret-up-down] text-base-content absolute end-3 top-1/2 size-4 shrink-0 -translate-y-1/2" data-combo-box-toggle="" ></span>
</div>
<div class="bg-base-100 rounded-box shadow-base-300/20 absolute z-50 max-h-44 w-full space-y-0.5 overflow-y-auto p-2 shadow-lg" style="display: none" data-combo-box-output="" >
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="0" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="Venezuela" data-combo-box-value="">Venezuela</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="1" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="Papua New Guinea" data-combo-box-value="">Papua New Guinea</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="2" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="South Africa " data-combo-box-value="">South Africa</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="3" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="Honduras" data-combo-box-value="">Honduras</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="4" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="India" data-combo-box-value="">India</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="5" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="El Salvador" data-combo-box-value="">El Salvador</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
</div>
</div>A JSON-based ComboBox example.
A ComboBox, a dropdown component allowing users to type for suggestions, is being set up. The root div includes an attribute apiUrl, indicating the ComboBox where to retrieve data.
In this instance, it’s set to https://www.freetestapi.com/api/v1/countries, used to obtain a list of countries.
Another attribute, outputItemTemplate, defines the layout for each item within the dropdown menu. It comprises HTML structure incorporating data-combo-box-output-item to represent individual dropdown items. Each item includes a section for the name (utilizing data-combo-box-output-item-field="name") and a span for a checkmark icon, visible upon item selection.
<div class="relative max-w-sm"
data-combo-box='{
"apiUrl": "https://www.freetestapi.com/api/v1/countries",
"outputItemTemplate": "<div class=\"dropdown-item combo-box-selected:dropdown-active\" data-combo-box-output-item><div class=\"flex justify-between items-center w-full\"><div data-combo-box-output-item-field=\"name\" data-combo-box-search-text data-combo-box-value></div><span class=\"icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0\"></span></div></div>"
}' >
<div class="relative">
<input class="input" type="text" value="India" role="combobox" aria-expanded="false" data-combo-box-input="" aria-label="Json-based combobox" />
<span class="icon-[tabler--caret-up-down] text-base-content absolute end-3 top-1/2 size-4 shrink-0 -translate-y-1/2" data-combo-box-toggle="" ></span>
</div>
<div class="bg-base-100 rounded-box shadow-base-300/20 absolute z-50 max-h-44 w-full space-y-0.5 overflow-y-auto p-2 shadow-lg" style="display: none" data-combo-box-output="" ></div>
</div>A JSON-configured ComboBox that retrieves options from an API. apiSearchPath specifies the API endpoint for searching items. apiSearchDefaultPath sets the default API endpoint to load all items initially.<div class="relative max-w-sm"
data-combo-box='{
"apiUrl": "https://restcountries.com/v3.1",
"apiSearchPath": "name",
"apiSearchDefaultPath": "all",
"outputItemTemplate": "<div class=\"dropdown-item combo-box-selected:dropdown-active\" data-combo-box-output-item><div class=\"flex justify-between items-center w-full\"><div><div class=\"hidden\" data-combo-box-output-item-field=\"ccn3\"></div><div data-combo-box-output-item-field=\"name.common\" data-combo-box-search-text data-combo-box-value></div></div><span class=\"icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0\"></span></div></div>"
}' >
<div class="relative">
<input class="input" type="text" value="India" role="combobox" aria-expanded="false" data-combo-box-input="" aria-label="based on API pathes combobox" />
<span class="icon-[tabler--caret-up-down] text-base-content absolute end-3 top-1/2 size-4 shrink-0 -translate-y-1/2" data-combo-box-toggle="" ></span>
</div>
<div class="bg-base-100 rounded-box shadow-base-300/20 absolute z-50 max-h-44 w-full space-y-0.5 overflow-y-auto p-2 shadow-lg" style="display: none" data-combo-box-output="" ></div>
</div>
:apiSearchQuery serves as a property or parameter containing the key name utilized for searching within a dataset when making API calls. Usually, it’s combined with user-entered text to generate a query string, which is then appended to the base API endpoint (apiUrl), resulting in the complete URL required to fetch the data.
:apiQuery represents additional query parameters for the API request, such as limit. :outputEmptyTemplate enables you to specify the content to display when no matching options are available.
The following example demonstrates the usage of search and limit parameters in a combo box.
<div class="relative max-w-sm"
data-combo-box='{
"apiUrl": "https://www.freetestapi.com/api/v1/countries",
"apiQuery": "limit=7",
"apiSearchQuery": "search",
"outputEmptyTemplate": "<div class=\"dropdown-item\">No countries found...</div>",
"outputItemTemplate": "<div class=\"dropdown-item combo-box-selected:dropdown-active\" data-combo-box-output-item><div class=\"flex justify-between items-center w-full\"><div data-combo-box-output-item-field=\"name\" data-combo-box-search-text data-combo-box-value></div><span class=\"icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0\"></span></div></div>"
}' >
<div class="relative">
<input class="input" type="text" value="India" role="combobox" aria-expanded="false" data-combo-box-input="" aria-label="Parameters in combobox" />
<span class="icon-[tabler--caret-up-down] text-base-content absolute end-3 top-1/2 size-4 shrink-0 -translate-y-1/2" data-combo-box-toggle="" ></span>
</div>
<div class="bg-base-100 rounded-box shadow-base-300/20 absolute z-50 max-h-44 w-full space-y-0.5 overflow-y-auto p-2 shadow-lg" style="display: none;" data-combo-box-output="" ></div>
</div>Set "minSearchLength": 2 to define the minimum number of characters required before initiating a search.
<div class="relative max-w-sm"
data-combo-box='{
"apiUrl": "https://www.freetestapi.com/api/v1/countries",
"apiQuery": "limit=15",
"minSearchLength": 2,
"apiSearchQuery": "search",
"outputEmptyTemplate": "<div class=\"dropdown-item\">No countries found...</div>",
"outputItemTemplate": "<div class=\"dropdown-item combo-box-selected:dropdown-active\" data-combo-box-output-item><div class=\"flex justify-between items-center w-full\"><div data-combo-box-output-item-field=\"name\" data-combo-box-search-text data-combo-box-value></div><span class=\"icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0\"></span></div></div>"
}' >
<div class="relative">
<input class="input" type="text" value="India" role="combobox" aria-expanded="false" data-combo-box-input="" aria-label="Parameters in combobox" />
<span class="icon-[tabler--caret-up-down] text-base-content absolute end-3 top-1/2 size-4 shrink-0 -translate-y-1/2" data-combo-box-toggle="" ></span>
</div>
<div class="bg-base-100 rounded-box shadow-base-300/20 absolute z-50 max-h-44 w-full space-y-0.5 overflow-y-auto p-2 shadow-lg" style="display: none;" data-combo-box-output="" ></div>
</div>When isOpenOnFocus is enabled, the dropdown menu will automatically appear upon focusing on the input field.
Alternatively, users have the option to utilize the data-combo-box-toggle attribute, designating an element within the ComboBox responsible for toggling the visibility of the dropdown list.
<div class="relative max-w-sm"
data-combo-box='{
"apiUrl": "https://www.freetestapi.com/api/v1/countries",
"isOpenOnFocus": true,
"outputEmptyTemplate": "<div class=\"dropdown-item\">No countries found...</div>",
"outputItemTemplate": "<div class=\"dropdown-item combo-box-selected:dropdown-active\" data-combo-box-output-item> <div class=\"flex justify-between items-center w-full\"> <div data-combo-box-output-item-field=\"name\" data-combo-box-search-text data-combo-box-value></div><span class=\"icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0\"></span></div></div>"
}' >
<div class="relative">
<input class="input" type="text" value="India" role="combobox" aria-expanded="false" data-combo-box-input="" aria-label="open on focus combobox" />
<span class="icon-[tabler--caret-up-down] text-base-content absolute end-3 top-1/2 size-4 shrink-0 -translate-y-1/2" data-combo-box-toggle="" ></span>
</div>
<div class="bg-base-100 rounded-box shadow-base-300/20 absolute z-50 max-h-44 w-full space-y-0.5 overflow-y-auto p-2 shadow-lg" style="display: none" data-combo-box-output="" ></div>
</div>A basic usage of ComboBox with close button.
<div class="relative max-w-sm" data-combo-box="">
<div class="relative">
<input class="input" type="text" role="combobox" aria-expanded="false" value="" data-combo-box-input="" aria-label="Combobox with close button" />
<div class="combo-box-active:flex absolute inset-y-0 end-8 hidden items-center">
<button type="button" class="btn btn-sm btn-circle btn-text btn-primary" aria-label="Close" data-combo-box-close="" >
<span class="sr-only">Close</span>
<span class="icon-[tabler--xbox-x] size-4 shrink-0"></span>
</button>
</div>
<span class="icon-[tabler--caret-up-down] text-base-content absolute end-3 top-1/2 size-4 shrink-0 -translate-y-1/2" data-combo-box-toggle="" ></span>
</div>
<div class="bg-base-100 rounded-box shadow-base-300/20 absolute z-50 max-h-44 w-full space-y-0.5 overflow-y-auto p-2 shadow-lg" style="display: none" data-combo-box-output="" >
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="0" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="Venezuela" data-combo-box-value="">Venezuela</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="1" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="Papua New Guinea" data-combo-box-value="">Papua New Guinea</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="2" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="South Africa " data-combo-box-value="">South Africa</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="3" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="Honduras" data-combo-box-value="">Honduras</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="4" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="India" data-combo-box-value="">India</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="5" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="El Salvador" data-combo-box-value="">El Salvador</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
</div>
</div>Combo box html example with dropdown and modal.
Below is an example showcasing the utilization of the SearchBox within a dropdown, employing data attributes in HTML. Furthermore, the example illustrates how to create groups.
<div class="max-w-sm">
<div class="relative"
data-combo-box='{
"groupingType": "default",
"preventSelection": true,
"isOpenOnFocus": true,
"groupingTitleTemplate": "<div class=\"block text-xs text-base-content/50 m-3 mb-1\"></div>"
}' >
<div class="relative">
<input class="input ps-8" type="text" placeholder="Search for an action" role="combobox" aria-expanded="false" value="" data-combo-box-input="" />
<span class="icon-[tabler--search] text-base-content absolute start-3 top-1/2 size-4 shrink-0 -translate-y-1/2" ></span>
</div>
<div class="bg-base-100 rounded-box p-2 shadow-base-300/20 shadow-lg" style="display: none" data-combo-box-output="" >
<div data-combo-box-output-items-wrapper="" class="space-y-0.5">
<!-- Group: Recent Actions -->
<div data-combo-box-output-item='{"group": {"name": "recent", "title": "Recent Actions"}}' tabindex="0">
<a class="dropdown-item combo-box-selected:dropdown-active" href="#">
<span class="icon-[tabler--writing] text-base-content/80 size-5 shrink-0"></span>
<span class="text-base-content" data-combo-box-search-text="Write a document" data-combo-box-value="" >
Write a document
</span>
<span class="text-base-content/50 ms-auto hidden text-xs sm:inline" data-combo-box-search-text="Google Docs" data-combo-box-value="" >
Google Docs
</span>
</a>
</div>
<div data-combo-box-output-item='{"group": {"name": "recent", "title": "Recent Actions"}}' tabindex="1">
<a class="dropdown-item combo-box-selected:dropdown-active" href="#">
<span class="icon-[tabler--calendar] text-base-content/80 size-5 shrink-0"></span>
<span class="text-base-content" data-combo-box-search-text="Schedule a meeting" data-combo-box-value="" >
Schedule a meeting
</span>
<span class="text-base-content/50 ms-auto hidden text-xs sm:inline" data-combo-box-search-text="Google Calendar" data-combo-box-value="" >
Google Calendar
</span>
</a>
</div>
<div data-combo-box-output-item='{"group": {"name": "recent", "title": "Recent Actions"}}' tabindex="2">
<a class="dropdown-item combo-box-selected:dropdown-active" href="#">
<span class="icon-[tabler--presentation] text-base-content/80 size-5 shrink-0"></span>
<span class="text-base-content" data-combo-box-search-text="Create a presentation" data-combo-box-value="" >
Create a presentation
</span>
<span class="text-base-content/50 ms-auto hidden text-xs sm:inline" data-combo-box-search-text="Microsoft PowerPoint" data-combo-box-value="" >
PowerPoint
</span>
</a>
</div>
<!-- Group: People -->
<div data-combo-box-output-item='{"group": {"name": "people", "title": "People"}}' tabindex="4">
<a class="dropdown-item combo-box-selected:dropdown-active" href="#">
<img class="size-6 shrink-0 rounded-full" src="https://cdn.flyonui.com/fy-assets/avatar/avatar-2.png" alt="Image Description" />
<span class="text-base-content" data-combo-box-search-text="Alice Johnson" data-combo-box-value="" >
Alice Johnson
</span>
<span class="ms-auto text-xs text-teal-600" data-combo-box-search-text="Online" data-combo-box-value="">
Online
</span>
</a>
</div>
<div data-combo-box-output-item='{"group": {"name": "people", "title": "People"}}' tabindex="5">
<a class="dropdown-item combo-box-selected:dropdown-active" href="#">
<img class="size-6 shrink-0 rounded-full" src="https://cdn.flyonui.com/fy-assets/avatar/avatar-11.png" alt="Image Description" />
<span class="text-base-content" data-combo-box-search-text="David Kim" data-combo-box-value="">
David Kim
</span>
<span class="text-base-content/50 ms-auto text-xs" data-combo-box-search-text="Offline" data-combo-box-value="" >
Offline
</span>
</a>
</div>
<div data-combo-box-output-item='{"group": {"name": "people", "title": "People"}}' tabindex="6">
<a class="dropdown-item combo-box-selected:dropdown-active" href="#">
<img class="size-6 shrink-0 rounded-full" src="https://cdn.flyonui.com/fy-assets/avatar/avatar-12.png" alt="Image Description" />
<span class="text-base-content" data-combo-box-search-text="Rosa Martinez" data-combo-box-value="" >
Rosa Martinez
</span>
<span class="text-base-content/50 ms-auto text-xs" data-combo-box-search-text="Offline" data-combo-box-value="" >
Offline
</span>
</a>
</div>
</div>
</div>
</div>
</div>A combo box displaying HTML content within a modal.
Press Shift + : for SearchBox.
<h5 class="text-base-content text-base"> Press <kbd class="kbd kbd-sm">Shift</kbd> + <kbd class="kbd kbd-sm">:</kbd> for SearchBox. </h5>
<!-- SearchBox Trigger -->
<button type="button" class="hidden" aria-haspopup="dialog" aria-expanded="false" aria-controls="html-modal-combo-box" data-overlay="#html-modal-combo-box" ></button>
<div id="html-modal-combo-box" class="overlay modal overlay-open:opacity-100 overlay-open:duration-300 hidden" role="dialog" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="relative"
data-combo-box='{
"preventVisibility": true,
"groupingType": "default",
"preventSelection": true,
"isOpenOnFocus": true,
"groupingTitleTemplate": "<div class=\"block text-xs text-base-content/50 m-3 mb-1\"></div>"
}' >
<div class="modal-header block">
<div class="relative">
<input class="input ps-8" type="text" placeholder="Search or type a command" role="combobox" aria-expanded="false" value="" autofocus="" data-combo-box-input="" />
<span class="icon-[tabler--search] text-base-content absolute start-3 top-1/2 size-4 shrink-0 -translate-y-1/2" data-combo-box-toggle="" ></span>
</div>
</div>
<!-- SearchBox Modal Body -->
<div class="modal-body overflow-y-auto mt-0 max-h-72 p-1.5" data-combo-box-output="">
<div class="space-y-0.5 p-0.5" data-combo-box-output-items-wrapper="">
<!-- Group: Recent Actions -->
<div data-combo-box-output-item='{"group": {"name": "recent", "title": "Recent Actions"}}' tabindex="0">
<a class="dropdown-item combo-box-selected:dropdown-active" href="#">
<span class="icon-[tabler--writing] text-base-content/80 size-4 shrink-0"></span>
<span class="text-base-content text-sm" data-combo-box-search-text="Write a document" data-combo-box-value="" >
Write a document
</span>
<span class="text-base-content/50 ms-auto hidden text-xs sm:inline" data-combo-box-search-text="Google Docs" data-combo-box-value="" >
Google Docs
</span>
</a>
</div>
<div data-combo-box-output-item='{"group": {"name": "recent", "title": "Recent Actions"}}' tabindex="1">
<a class="dropdown-item combo-box-selected:dropdown-active" href="#">
<span class="icon-[tabler--calendar] text-base-content/80 size-4 shrink-0"></span>
<span class="text-base-content text-sm" data-combo-box-search-text="Schedule a meeting" data-combo-box-value="" >
Schedule a meeting
</span>
<span class="text-base-content/50 ms-auto hidden text-xs sm:inline" data-combo-box-search-text="Google Calendar" data-combo-box-value="" >
Google Calendar
</span>
</a>
</div>
<div data-combo-box-output-item='{"group": {"name": "recent", "title": "Recent Actions"}}' tabindex="2">
<a class="dropdown-item combo-box-selected:dropdown-active" href="#">
<span class="icon-[tabler--presentation] text-base-content/80 size-4 shrink-0"></span>
<span class="text-base-content text-sm" data-combo-box-search-text="Create a presentation" data-combo-box-value="" >
Create a presentation
</span>
<span class="text-base-content/50 ms-auto hidden text-xs sm:inline" data-combo-box-search-text="Microsoft PowerPoint" data-combo-box-value="" >
PowerPoint
</span>
</a>
</div>
<!-- Group: People -->
<div data-combo-box-output-item='{"group": {"name": "people", "title": "People"}}' tabindex="4">
<a class="dropdown-item combo-box-selected:dropdown-active" href="#">
<img class="size-5 shrink-0 rounded-full" src="https://cdn.flyonui.com/fy-assets/avatar/avatar-2.png" alt="Image Description" />
<span class="text-base-content text-sm" data-combo-box-search-text="Alice Johnson" data-combo-box-value="" >
Alice Johnson
</span>
<span class="ms-auto text-xs text-teal-600" data-combo-box-search-text="Online" data-combo-box-value="">
Online
</span>
</a>
</div>
<div data-combo-box-output-item='{"group": {"name": "people", "title": "People"}}' tabindex="5">
<a class="dropdown-item combo-box-selected:dropdown-active" href="#">
<img class="size-5 shrink-0 rounded-full" src="https://cdn.flyonui.com/fy-assets/avatar/avatar-11.png" alt="Image Description" />
<span class="text-base-content text-sm" data-combo-box-search-text="David Kim" data-combo-box-value="" >
David Kim
</span>
<span class="text-base-content/50 ms-auto text-xs" data-combo-box-search-text="Offline" data-combo-box-value="" >
Offline
</span>
</a>
</div>
<div data-combo-box-output-item='{"group": {"name": "people", "title": "People"}}' tabindex="6">
<a class="dropdown-item combo-box-selected:dropdown-active" href="#">
<img class="size-5 shrink-0 rounded-full" src="https://cdn.flyonui.com/fy-assets/avatar/avatar-12.png" alt="Image Description" />
<span class="text-base-content text-sm" data-combo-box-search-text="Rosa Martinez" data-combo-box-value="" >
Rosa Martinez
</span>
<span class="text-base-content/50 ms-auto text-xs" data-combo-box-search-text="Offline" data-combo-box-value="" >
Offline
</span>
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div><script>
window.addEventListener('load', () => {
//HTML modal combo box
const htmlOverlay = HSOverlay.getInstance('#html-modal-combo-box', true)
const htmlCombobox = HSComboBox.getInstance('#html-modal-combo-box [data-combo-box]', true)
window.addEventListener('keydown', function (evt) {
if (evt.code === 'Semicolon' && evt.shiftKey) {
if (htmlOverlay.element && htmlOverlay.element.el.classList.contains('open')) return false
htmlOverlay.element.open()
htmlCombobox.element.setCurrent()
}
})
})
</script>Combo box example using JSON data displayed within a dropdown and a modal.
Utilizing a JSON example in a dropdown, use option :apiGroupField to select a heading. Positions are categorized as headings in this scenario.
<div class="max-w-sm">
<div class="relative"
data-combo-box='{
"groupingType": "default",
"isOpenOnFocus": true,
"apiUrl": "/docs/json/searchbox.json",
"apiGroupField": "position",
"outputItemTemplate": "<div class=\"dropdown-item combo-box-selected:dropdown-active\" data-combo-box-output-item> <div class=\"flex items-center justify-between\"> <div class=\"flex items-center w-full\"> <div class=\"flex items-center justify-center rounded-full bg-base-200 size-6 overflow-hidden me-2.5\"> <img class=\"shrink-0\" data-combo-box-output-item-attr='[{\"valueFrom\": \"image\", \"attr\": \"src\"}, {\"valueFrom\": \"name\", \"attr\": \"alt\"}]' /> </div> <div data-combo-box-output-item-field=\"name\" data-combo-box-search-text data-combo-box-value></div> </div> <span class=\"icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0\"> </span> </div> </div>","groupingTitleTemplate": "<div class=\"block text-xs text-base-content/50 m-3 mb-1\"></div>"
}' >
<!-- SearchBox -->
<div class="relative">
<input class="input ps-8" type="text" placeholder="Search or type a command" role="combobox" aria-expanded="false" value="" autofocus="" data-combo-box-input="" />
<span class="icon-[tabler--search] text-base-content absolute start-3 top-1/2 size-4 shrink-0 -translate-y-1/2" ></span>
</div>
<!-- SearchBox Body -->
<div class="bg-base-100 rounded-box shadow-base-300/20 absolute z-50 max-h-56 w-full space-y-0.5 overflow-y-auto p-2 shadow-lg" style="display: none" data-combo-box-output="" ></div>
</div>
</div>Combo box with json data show in modal.
Press Shift + t for SearchBox.
<h5 class="text-base-content text-base"> Press <kbd class="kbd kbd-sm">Shift</kbd> + <kbd class="kbd kbd-sm">t</kbd> for SearchBox. </h5>
<!-- SearchBox Trigger -->
<button type="button" class="hidden" aria-haspopup="dialog" aria-expanded="false" aria-controls="json-modal-combo-box" data-overlay="#json-modal-combo-box" ></button>
<!-- SearchBox Modal -->
<div id="json-modal-combo-box" class="overlay modal overlay-open:opacity-100 overlay-open:duration-300 hidden" role="dialog" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="relative"
data-combo-box='{
"preventVisibility": true,
"groupingType": "default",
"apiUrl": "/docs/json/searchbox.json",
"apiGroupField": "position",
"outputItemTemplate": "<div class=\"dropdown-item combo-box-selected:dropdown-active\" data-combo-box-output-item> <div class=\"flex items-center justify-between\"> <div class=\"flex items-center w-full\"> <div class=\"flex items-center justify-center rounded-full bg-base-200 size-6 overflow-hidden me-2.5\"> <img class=\"shrink-0\" data-combo-box-output-item-attr='[{\"valueFrom\": \"image\", \"attr\": \"src\"}, {\"valueFrom\": \"name\", \"attr\": \"alt\"}]' /> </div> <div data-combo-box-output-item-field=\"name\" data-combo-box-search-text data-combo-box-value></div> </div> <span class=\"icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0\"> </span> </div> </div>",
"groupingTitleTemplate": "<div class=\"block text-xs text-base-content/50 m-3 mb-1\"></div>"
}' >
<!-- SearchBox -->
<div class="modal-header block">
<div class="relative">
<input class="input ps-8" type="text" placeholder="Search or type a command" role="combobox" aria-expanded="false" value="" autofocus="" data-combo-box-input="" />
<span class="icon-[tabler--search] text-base-content absolute start-3 top-1/2 size-4 shrink-0 -translate-y-1/2" ></span>
</div>
</div>
<!-- SearchBox Modal Body -->
<div class="modal-body" data-combo-box-output="">
<div class="overflow-y-auto max-h-72 space-y-0.5" data-combo-box-output-items-wrapper="" ></div>
</div>
</div>
</div>
</div>
</div><script>
window.addEventListener('load', () => {
//Json modal combo box
const jsonOverlay = HSOverlay.getInstance('#json-modal-combo-box', true)
const jsonCombobox = HSComboBox.getInstance('#json-modal-combo-box [data-combo-box]', true)
window.addEventListener('keydown', function (evt) {
if (evt.code === 'KeyT' && evt.shiftKey) {
if (jsonOverlay.element && jsonOverlay.element.el.classList.contains('open')) return false
jsonOverlay.element.open()
jsonCombobox.element.setCurrent()
}
})
})
</script>Combo box example demonstrating tab filtering functionality, incorporating both dropdown and modal components.
Experience tab filtering within a dropdown. Set :groupingType to tabs, utilize :groupingTitleTemplate to style the filtering tabs, and :tabsWrapperTemplate to style the tab wrapper.
<div class="max-w-sm">
<div
class="relative"
data-combo-box='{
"groupingType": "tabs",
"isOpenOnFocus": true,
"apiUrl": "https://fakestoreapi.com/products",
"apiGroupField": "category",
"outputItemTemplate": "<div class=\"dropdown-item combo-box-selected:dropdown-active\" data-combo-box-output-item> <div class=\"flex justify-between items-center w-full\"> <div class=\"truncate\" data-combo-box-output-item-field=\"title\" data-combo-box-search-text data-combo-box-value></div> <span class=\"icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0\"> </span> </div> </div>",
"groupingTitleTemplate": "<button type=\"button\" class=\"btn btn-sm btn-text capitalize combo-box-tab-active:btn-active\"></button>",
"tabsWrapperTemplate": "<div class=\"overflow-x-auto mb-1 pb-2\"></div>"
}' >
<!-- SearchBox -->
<div class="relative">
<input class="input ps-8" type="text" placeholder="Search or type a command" role="combobox" aria-expanded="false" value="" autofocus="" data-combo-box-input="" />
<span class="icon-[tabler--search] text-base-content absolute start-3 top-1/2 size-4 shrink-0 -translate-y-1/2" ></span>
</div>
<!-- SearchBox body -->
<div class="bg-base-100 rounded-box shadow-base-300/20 absolute z-50 max-h-56 w-full overflow-y-auto p-2 shadow-lg" style="display: none" data-combo-box-output="" >
<div data-combo-box-output-items-wrapper="" class="space-y-0.5"></div>
</div>
</div>
</div>In this example, a modal popup is employed to provide a user-friendly tab filtering experience.
Press \ for SearchBox.
<h5 class="text-base-content text-base"> Press <kbd class="kbd kbd-sm">\</kbd> for SearchBox. </h5>
<!-- SearchBox Trigger -->
<button type="button" class="hidden" aria-haspopup="dialog" aria-expanded="false" aria-controls="tab-modal-combo-box" data-overlay="#tab-modal-combo-box" ></button>
<!-- SearchBox Modal -->
<div id="tab-modal-combo-box" class="overlay modal overlay-open:opacity-100 overlay-open:duration-300 hidden" role="dialog" tabindex="-1">
<div class="modal-dialog overflow-x-hidden">
<div class="modal-content max-h-full">
<div class="relative"
data-combo-box='{
"preventVisibility": true,
"groupingType": "tabs",
"isOpenOnFocus": true,
"apiUrl": "https://fakestoreapi.com/products",
"apiGroupField": "category",
"outputItemTemplate": "<div class=\"dropdown-item combo-box-selected:dropdown-active\" data-combo-box-output-item> <div class=\"flex justify-between items-center w-full\"> <div class=\"truncate\" data-combo-box-output-item-field=\"title\" data-combo-box-search-text data-combo-box-value></div> <span class=\"icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0\"> </span> </div> </div>",
"groupingTitleTemplate": "<button type=\"button\" class=\"btn btn-sm btn-text capitalize combo-box-tab-active:btn-active\"></button>",
"tabsWrapperTemplate": "<div class=\"overflow-x-auto mb-1 pb-2\"></div>"
}' >
<div class="modal-header block">
<div class="relative">
<input class="input ps-8" type="text" placeholder="Search or type a command" role="combobox" aria-expanded="false" value="" autofocus="" data-combo-box-input="" />
<span class="icon-[tabler--search] text-base-content absolute start-3 top-1/2 size-4 shrink-0 -translate-y-1/2" ></span>
</div>
</div>
<!-- SearchBox Modal Body -->
<div class="modal-body" data-combo-box-output="">
<div class="overflow-y-auto max-h-72 space-y-0.5" data-combo-box-output-items-wrapper="" ></div>
</div>
</div>
</div>
</div>
</div><script>
window.addEventListener('load', () => {
//tab modal combo box
const tabOverlay = HSOverlay.getInstance('#tab-modal-combo-box', true)
const tabCombobox = HSComboBox.getInstance('#tab-modal-combo-box [data-combo-box]', true)
window.addEventListener('keydown', function (evt) {
if (evt.code === 'Backslash') {
if (tabOverlay.element && tabOverlay.element.el.classList.contains('open')) return false
tabOverlay.element.open()
tabCombobox.element.setCurrent()
}
})
})
</script>destroy method is provided to facilitate the destruction of a toggle count.<div id="combo-box-to-destroy" class="relative max-w-sm" data-combo-box="">
<div class="relative">
<input class="input" type="text" value="India" role="combobox" aria-expanded="false" data-combo-box-input="" aria-label="Combobox Destroy" />
<span class="icon-[tabler--caret-up-down] text-base-content absolute end-3 top-1/2 size-4 shrink-0 -translate-y-1/2" data-combo-box-toggle="" ></span>
</div>
<div class="bg-base-100 rounded-box shadow-base-300/20 absolute z-50 max-h-44 w-full space-y-0.5 overflow-y-auto p-2 shadow-lg" style="display: none" data-combo-box-output="" >
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="0" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="Venezuela" data-combo-box-value="">Venezuela</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="1" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="Papua New Guinea" data-combo-box-value="">Papua New Guinea</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="2" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="South Africa " data-combo-box-value="">South Africa</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="3" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="Honduras" data-combo-box-value="">Honduras</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="4" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="India" data-combo-box-value="">India</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="5" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="El Salvador" data-combo-box-value="">El Salvador</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
</div>
</div>
<div class="mt-4 flex gap-3">
<button class="btn btn-primary" id="destroy-btn">Destroy</button>
<button class="btn btn-primary" id="reinit-btn" disabled>Reinitialize</button>
</div><script>
window.addEventListener('load', () => {
// Destroy and reinit variables
const combobox = document.querySelector('#combo-box-to-destroy')
const destroyBtn = document.querySelector('#destroy-btn')
const reinitBtn = document.querySelector('#reinit-btn')
// Destroy usage
destroyBtn.addEventListener('click', () => {
const { element } = HSComboBox.getInstance(combobox, true)
element.destroy()
destroyBtn.setAttribute('disabled', 'disabled')
reinitBtn.removeAttribute('disabled')
})
// Reinit usage
reinitBtn.addEventListener('click', () => {
HSComboBox.autoInit()
reinitBtn.setAttribute('disabled', 'disabled')
destroyBtn.removeAttribute('disabled')
})
})
</script>COMMAND | DESCRIPTION |
|---|---|
| Enter | Activates the selected tab. |
A-Z a-z | Focuses first item that matches keyboard input. |
Home End | Focuses first/last non-disabled item. |
| Esc | Closes any open Menus. |
| Focuses previous/next non-disabled item. |
PARAMETERS | DESCRIPTION | OPTIONS | DEFAULT VALUE |
|---|---|---|---|
| General Options | |||
data-combo-box | Activates a ComboBox on a specific element. | — | — |
:gap | Defines the gap between the input field and the dropdown list. | number | 6 |
:viewport | Specifies the parent element for calculating dropdown list position, by default relative to the document. | string, HTMLElement | — |
:preventVisibility | If true, prevents visibility changes in the ComboBox. | boolean | false |
:preventSelection | If true, prevents item selection in the dropdown list. | boolean | false |
:isOpenOnFocus | If true, the dropdown list opens when the field is focused. | boolean | false |
:groupingType | Type of grouping used in the dropdown. | default, tags | — |
:groupingTitleTemplate | Template for the title in grouped ComboBox. | One line HTML markup | — |
:preventAutoPosition | If true, it disables dropdown auto-positioning. | boolean | false |
:preventClientFiltering | If true, it disables client-side filtering. | boolean | true (if :apiSearchQuery is not empty) |
:tabsWrapperTemplate | Template for the tabs wrapper in the ComboBox. | One line HTML markup | <div class="overflow-x-auto p-4"></div> |
:keepOriginalOrder | If true, it keeps the original order of items. | boolean | false |
:preserveSelectionOnEmpty | If true, it preserves the selected value when the input is empty. | boolean | true |
:minSearchLength | Sets the minimum number of characters required to activate the search functionality. | number | 0 |
| API Options | |||
:apiUrl | The URL endpoint for fetching data via API. | string, null | — |
:apiDataPart | Specifies the part of the returned data to use as the primary data array. | string, null | — |
:apiQuery | Parameters for API requests, like limiting results. | string, null | — |
:apiSearchQuery | Parameter name used for search queries. | string, null | — |
:apiHeaders | Headers to include in API requests. | object | {} |
:apiGroupField | Field in the API response used for data grouping. | string, null | — |
:apiSearchPath | A string that specifies the endpoint path for the API request, excluding the base URL. For example, if the full API URL is https://some-api.com/part/of/the/url, apiSearchPath should be set to part/of/the/url. Note: The parameters apiSearchPath and apiSearchDefaultPath are mutually exclusive with apiSearchQuery. Only one of these options should be used in a request to define the API endpoint path. | string, null | — |
:apiSearchDefaultPath | A string that defines the default API endpoint path to be used when the input field is empty or an empty request is sent. This path provides a fallback for requests without specific search terms. For example, if the full API URL is https://some-api.com/countries/all, set apiSearchDefaultPath to countries/all. Note: The parameters apiSearchPath and apiSearchDefaultPath are mutually exclusive with apiSearchQuery. Only one of these options should be used in a request to define the API endpoint path. | string, null | — |
| Template Options | |||
:outputItemTemplate | Template for individual items in the dropdown list. | string, null | <div class="dropdown-item combo-box-selected:dropdown-active" data-combo-box-output-item> ... </div> |
:outputEmptyTemplate | Template for when no data is found in the dropdown. | string, null | Nothing found... |
:outputLoaderTemplate | Template for the loader when fetching data. | string, null | <span class="loading loading-spinner text-primary"></span> |
:searchWrapperTemplate | Template for the search field wrapper. | string, null | <div></div> |
| Input & Output Options | |||
data-combo-box-input | Identifies the element responsible for data entry in the ComboBox. | — | — |
data-combo-box-output | Identifies the element that outputs data from the ComboBox. | — | — |
data-combo-box-toggle | Element that toggles the dropdown list. | — | — |
data-combo-box-open | Element that open the dropdown list. | — | — |
data-combo-box-close | Element that close the dropdown list. | — | — |
data-combo-box-output-item | Defines an element within the initialized container that will handle the display of each individual data item. | — | — |
> data-combo-box-search-text | Defines the element within which text will be searched. | — | — |
> data-combo-box-value | Defines an element whose text will be set as a value when selected. | — | — |
> data-combo-box-output-item-field | Defines a data field that will be taken to fill the element with text. | — | — |
> data-combo-box-output-item-attr | Defines the attributes that will be filled with the corresponding data. For example, the src attribute of an image. | — | — |
:valueFrom | Field name from which data will be taken. | string | — |
:attr | Attribute name where data will be supplied. | string | — |
The HSCombobox object is contained within the global window object.
METHOD | DESCRIPTION | ||
|---|---|---|---|
| PUBLIC METHODS | |||
getCurrentData | Returns the data of the selected element as an object. This data must first be assigned as a value to the data parameter data-combo-box-item-stored-data, when standard rendering. And when rendering via the API, the data is automatically substituted into the data attribute (no need to do it yourself). | ||
open() | Opens the autosuggestion list. | ||
close() | Closes the autosuggestion list. | ||
recalculateDirection() | Forces recalculation of the autosuggestion list’s positions. | ||
destroy() | Destroys the instance, removes generated markup (if any), removes added classes and attributes. | ||
| STATIC METHODS | |||
HSCombobox.getInstance(target, isInstance) | Returns the element associated with the target.
| ||
HSCombobox.autoInit() | Reinitializes all ComboBoxes on the page. | ||
HSCombobox.close(target) | Closes the target ComboBox.
| ||
HSCombobox.closeCurrentlyOpened() | Closes the currently opened ComboBox. | ||
Below, is the demonstration on how to use the methods. To test other methods, copy the following methods into your console and click the button.
<!-- Basic ComboBox structure with JavaScript event handling -->
<div class="relative max-w-sm" id="combo-box-method" data-combo-box="">
<div class="relative">
<input class="input" type="text" value="India" role="combobox" aria-expanded="false" data-combo-box-input="" aria-label="Default combobox" />
<span class="icon-[tabler--caret-up-down] text-base-content absolute end-3 top-1/2 size-4 shrink-0 -translate-y-1/2" data-combo-box-toggle="" ></span>
</div>
<div class="bg-base-100 rounded-box shadow-base-300/20 absolute z-50 max-h-44 w-full space-y-0.5 overflow-y-auto p-2 shadow-lg" style="display: none" data-combo-box-output="" >
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="0" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="Venezuela" data-combo-box-value="">Venezuela</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="1" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="Papua New Guinea" data-combo-box-value="">Papua New Guinea</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="2" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="South Africa " data-combo-box-value="">South Africa</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="3" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="Honduras" data-combo-box-value="">Honduras</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="4" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="India" data-combo-box-value="">India</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="5" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="El Salvador" data-combo-box-value="">El Salvador</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
</div>
</div>
<button id="open-btn" class="btn btn-primary mt-4 absolute top-28 sm:top-2 sm:end-6">Open ComboBox</button><script>
window.addEventListener('load', function () {
const comboBox = new HSComboBox(document.querySelector('#combo-box-method'))
const openBtn = document.querySelector('#open-btn')
openBtn.addEventListener('click', () => {
comboBox.open()
})
})
</script>Open item (public method).
// This method is used in above example.
const comboBox = new HSComboBox(document.querySelector('#combo-box-method'));
const openBtn = document.querySelector('#open-btn')
openBtn.addEventListener('click', () => {
comboBox.open()
})Open item (mixed).
const { element } = HSComboBox.getInstance('#combo-box-method', true);
const openBtn = document.querySelector('#open-btn');
openBtn.addEventListener('click', () => {
element.open();
});Destroy instance.
const { element } = HSComboBox.getInstance('#combo-box-to-destroy', true);
const destroyBtn = document.querySelector('#destroy-btn');
destroyBtn.addEventListener('click', () => {
element.destroy();
});METHOD | DESCRIPTION | RETURNING VALUE |
|---|---|---|
on:select | Called when any select is changed. | Current value |
Display a console log message when an option is selected.
<div class="relative max-w-sm" id="combo-box-event" data-combo-box="">
<div class="relative">
<input class="input" type="text" value="India" role="combobox" aria-expanded="false" data-combo-box-input="" aria-label="Default combobox" />
<span class="icon-[tabler--caret-up-down] text-base-content absolute end-3 top-1/2 size-4 shrink-0 -translate-y-1/2" data-combo-box-toggle="" ></span>
</div>
<div class="bg-base-100 rounded-box shadow-base-300/20 absolute z-50 max-h-44 w-full space-y-0.5 overflow-y-auto p-2 shadow-lg" style="display: none" data-combo-box-output="" >
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="0" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="Venezuela" data-combo-box-value="">Venezuela</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="1" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="Papua New Guinea" data-combo-box-value="">Papua New Guinea</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="2" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="South Africa " data-combo-box-value="">South Africa</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="3" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="Honduras" data-combo-box-value="">Honduras</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="4" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="India" data-combo-box-value="">India</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
<div class="dropdown-item combo-box-selected:dropdown-active" tabindex="5" data-combo-box-output-item="">
<div class="flex items-center justify-between">
<span data-combo-box-search-text="El Salvador" data-combo-box-value="">El Salvador</span>
<span class="icon-[tabler--check] text-primary combo-box-selected:block hidden size-4 shrink-0"></span>
</div>
</div>
</div>
</div><script>
window.addEventListener('load', () =>
const comboBoxEvent = HSComboBox.getInstance('#combo-box-event', true).element
comboBoxEvent.on('select', value => {
console.log(comboBoxEvent.value)
})
)
</script>When select changes event example.
const {element} = HSComboBox.getInstance('#event-select', true);
element.on('select', (value) => {console.log("element.value")});