Listbox placeholder text
See original GitHub issueHi 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>
)
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:8
Top Results From Across the Web
How to make a placeholder in a listBox - Stack Overflow
to achieve your example you should use dropDownList instead of listBox echo $form->field($model, 'additionalRoles', [ 'options' => [ 'class' ...
Read more >HeaderTitle or Placeholder for Listbox? | Angular - EJ 2 Forums
In the "value" I'm only getting the text, and the id is just 0, 1, etc.. I tried to add something like. [fields]="{...
Read more >In a responsive web app, does the ListBox allow placeholder ...
In a responsive web app, does the ListBox allow placeholder text? I am not able to get placeholder text to work with a...
Read more >How to Make a Placeholder for a Select Box in HTML
Answer: Use the disabled and selected Attribute. There is no attribute like input's placeholder for select box dropdown. However, you can create similar...
Read more >Como colocar placeholder em listBox com Select2 - OutSystems
If you are using a listBox you can use "data-placeholder" as a extended property and as value use the text you want. This...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@OneTuskedMario not sure what you are trying to do, but you can add a placeholder to the input like this:
@amrithmmh exactly as the OP stated. Just make sure to not use any value or label from the selectedOption without checking if it exists.