- Plugins
- Combobox
Plugins
Tailwind CSS ComboBox
Dynamic suggestions as users type in an input field.
Installation
To get started, install ComboBox plugin via npm, else you can skip this step if you are already using Preline UI as a package.
npm i @preline/combobox
Basic usage
Prefer to create your own style? Here is a completely unstylized example.
<div class="inline-flex relative" data-hs-combo-box>
<div class="relative">
<input type="text" role="combobox" aria-expanded="false" value="" data-hs-combo-box-input />
</div>
<div class="absolute z-50" style="display: none;" data-hs-combo-box-output>
<div class="cursor-pointer" tabindex="0" data-hs-combo-box-output-item>
<span data-hs-combo-box-search-text="1">1</span>
</div>
<div class="cursor-pointer" tabindex="1" data-hs-combo-box-output-item>
<span data-hs-combo-box-search-text="2">2</span>
</div>
</div>
</div>
Methods
The HSCombobox
object is contained within the global window
object
Open item (public method).
const comboBox = new HSComboBox(document.querySelector('#combo-box'));
const openBtn = document.querySelector('#open-btn');
openBtn.addEventListener('click', () => {
comboBox.open();
});
Open item (mixed).
const { element } = HSComboBox.getInstance('#combo-box', true);
const openBtn = document.querySelector('#open-btn');
openBtn.addEventListener('click', () => {
element.open();
});
Demo examples
Looking for prebuilt UI components based on the Tailwind CSS? Preline UI packs hundreds of component examples for all your website needs.
Check out Preline UI Components