question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Select the first option by default

See original GitHub issue

Reproduction link

https://stackblitz.com/

Steps to reproduce

This is a question

What is expected?

This is a question

What is actually happening?

This is a question

Environment Info
antd 4.22.6
React latest
System any
Browser any

Is there a way to set the first options in a select by default. For example,

<Form.Item >
        <Select 
                options={options}
                selectDefaultFirstOption={true} />
</Form.Item>

As options changes dynamically, the default value is always the first option element by default. I tried

  • initialValues in Form
  • initialValue in Form.Item
  • defaultValue in Select None of the above is working. Would any one kind enough in the ant design community enlighten me with the solution? Thanks a lot.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
XuQiYcommented, Aug 24, 2022

@Lantianyou Consider wrapping the Select For FormItem image

0reactions
Lantianyoucommented, Aug 24, 2022

Thank you !

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I set the default value for an HTML <select> element?
In the following example, when run, the first <select> should show option with the value user as selected, and the second <select> should...
Read more >
How to set the default value for an HTML <select> element
The option tag contains the value that would be used when selected. The default value of the select element can be set by...
Read more >
First option in select dropdown appears selected when no ...
No option should be selected when none of the options match the bound value. For my app it is important that select dropdowns...
Read more >
How to set the default value for an HTML ... - Educative.io
The challenge here is that, by default, the tag is displayed on the webpage with the first option. You will get this by...
Read more >
<select>: The HTML Select element - HTML - MDN Web Docs
If no value attribute is included, the value defaults to the text contained inside the element. You can include a selected attribute on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found