Interactive demos of hcg-autocomplete, a lightweight zero-dependency
combobox for <input> fields. Try local filtering, async sources,
multi-select chips, free-text values, and the JavaScript API.
Version .
hcg-autocomplete Full documentation
Type to filter a static list of city names.
hcgAutocomplete('#demo-basic', {
source: ['Amsterdam', 'Berlin', 'Copenhagen', 'London', 'Paris']
});
Use objects when the submitted value differs from the displayed label.
hcgAutocomplete('#demo-objects', {
source: [
{ value: 'us', label: 'United States' },
{ value: 'uk', label: 'United Kingdom' }
],
onChange: (input, value) => console.log(value)
});
Simulated API with setTimeout. Only the latest request is applied.
hcgAutocomplete('#demo-async', {
minChars: 1,
debounce: 250,
source: (query, done) => {
setTimeout(() => {
done(null, allItems.filter((item) =>
item.toLowerCase().includes(query.toLowerCase())
));
}, 400);
}
});
Suggestions appear after 2 characters with a 400ms debounce.
hcgAutocomplete('#demo-minchars', {
source: ['Red', 'Green', 'Blue', 'Cyan', 'Magenta'],
minChars: 2,
debounce: 400
});
Pick multiple tags. Press Backspace on an empty input to remove the last chip.
hcgAutocomplete('#demo-multi', {
multiple: true,
source: ['HTML', 'CSS', 'JavaScript', 'TypeScript', 'React', 'Vue']
});
Press Enter to commit a value that is not in the suggestion list.
hcgAutocomplete('#demo-custom', {
allowCustom: true,
source: ['gmail.com', 'outlook.com', 'yahoo.com']
});
Use setValue(), getValue(), and clear().
const api = hcgAutocomplete('#demo-api', {
clearable: true,
source: ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter']
});
api.setValue('Mars');
api.setValue('Jupiter', true); // silent: no change event
api.getValue();
api.clear();
A disabled input cannot open the suggestion panel.
<input id="demo-disabled" type="text" disabled>
const api = hcgAutocomplete('#demo-disabled');
api.enable();
api.disable();
Replace the suggestion list with setSource() or setOption('source', ...).
const api = hcgAutocomplete('#demo-source', {
source: ['Orange', 'Lemon', 'Lime']
});
api.setSource(['Strawberry', 'Blueberry', 'Raspberry']);
api.refresh();
All lifecycle callbacks logged below.
hcgAutocomplete('#demo-callbacks', {
source: ['Cat', 'Dog', 'Rabbit', 'Hamster'],
onInput: (input, query) => {},
onOpen: (input) => {},
onClose: (input) => {},
onSelect: (input, item) => {},
onChange: (input, value) => {}
});