-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
Hi there,
Wondering if there is some way you can recommend to provide placeholder text for a Listbox control?
i.e. some initial text that gets displayed but doesn't actually result in the Listbox having any selection value.
I was thinking you could have empty state to begin with and have some initial text in the <Listbox.Button>
For example:
import React, { useState } from 'react'
import { Listbox } from '@headlessui/react'
const people = [
{ id: 1, name: 'Durward Reynolds' },
{ id: 2, name: 'Kenton Towne' },
{ id: 3, name: 'Therese Wunsch' },
{ id: 4, name: 'Benedict Kessler' },
{ id: 5, name: 'Katelyn Rohan' },
]
function MyListbox() {
const [selectedPerson, setSelectedPerson] = useState()
return (
<Listbox value={selectedPerson} onChange={setSelectedPerson}>
<Listbox.Button>{selectedPerson ? selectedPerson.name : "Select person"}</Listbox.Button>
<Listbox.Options>
{people.map(person => (
<Listbox.Option key={person.id} value={person}>
{person.name}
</Listbox.Option>
))}
</Listbox.Options>
</Listbox>
)
}
rahulcn, chrusli, moaaz-bhnas, ortiz-antonio and theyarestories
Metadata
Metadata
Assignees
Labels
No labels