Combobox entries via API support #1881
gregjotau
started this conversation in
Ideas & Suggestions
Replies: 3 comments 3 replies
|
We wanted to get combobox out as soon as possible, so we intentionally skipped async + virtualization for the initial release. In fact, I'm not sure we want to do virtualization at all, as that would still require a DOM element for each option. We've been thinking about ways to handle filtering asynchronously, which would likely satisfy your use case, but that needs to be developed and vetted for accessibility. |
1 reply
|
@claviska any update on this? for now we have an "r-api-combobox" custom component for this? |
2 replies
|
Update: I just submitted a PR in core and Pro to support this. Items can be added one of two ways through the With value/label objects: combobox.dataSource = async ({ query, signal }) => {
const response = await fetch(`/api/countries?q=${encodeURIComponent(query)}`, { signal });
return response.json(); // [{ value: 'ca', label: 'Canada' }, ...]
};With HTML: <wa-combobox id="combobox-custom" label="Assignee" placeholder="Search people"></wa-combobox>
<script type="module">
const combobox = document.querySelector('#combobox-custom');
const people = [
{ value: 'ada', label: 'Ada Lovelace', icon: 'calculator' },
{ value: 'alan', label: 'Alan Turing', icon: 'key' },
{ value: 'grace', label: 'Grace Hopper', icon: 'anchor' },
{ value: 'katherine', label: 'Katherine Johnson', icon: 'rocket' },
];
// This stands in for a request to your server
combobox.dataSource = async ({ query }) => {
await new Promise(resolve => setTimeout(resolve, 500));
return people
.filter(person => person.label.toLowerCase().includes(query.toLowerCase()))
.map(
person => `
<wa-option value="${person.value}">
<wa-icon slot="start" name="${person.icon}"></wa-icon>
${person.label}
</wa-option>
`,
)
.join('');
};
</script> |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
We're going to test this week the new experimental combobox.
It does most of what we need seemingly based on the docs.
The only thing is getting the values from the API. TBH, for most comboboxes I think it will be fine to just server-side render all the available values. But there are cases ther might be 1000+ entries. And also cases where you might want to add an entry (in another tab or through modal, for example new customer when doing invoicing), and then for the combobox to update without a page refresh.
All reactions