JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdn.jsdelivr.net/gh/orchidjs/tom-select@1.2.1/dist/js/tom-select.complete.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/orchidjs/tom-select@1.2.1/dist/css/tom-select.bootstrap4.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.2/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css">
<div class="p-4"><select id="select-repo" placeholder="Pick a repository..." multiple></select>
</div>
JavaScript
new TomSelect('#select-repo',{
valueField: 'url',
labelField: 'name',
searchField: 'name',
// fetch remote data https://caniuse.com/fetch
shouldLoad:function(query){
if ( query.length < 3 ) return false;
return true;
},
load: function(query, callback) {
var url = 'https://api.github.com/search/repositories?q=' + encodeURIComponent(query);
fetch(url)
.then(response => response.json())
.then(json => {
callback(json.items);
}).catch(()=>{
callback();
});
},
// custom rendering functions for options and items
render: {
option: function(item, escape) {
return `<div>${ escape(item.name) }</div>`;
},
item: function(item, escape) {
return `<div>${ escape(item.name) }</div>`;
}
},
});