<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Default selecting an option with the Select component in Developer Q&amp;A Forum</title>
    <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Default-selecting-an-option-with-the-Select-component/m-p/201317#M119</link>
    <description>&lt;P&gt;Another straightforward solution to your problem would be setting the default value of the state variable to your default selection value:&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;const [selected, setSelected] = useState&amp;lt;SelectedKeys | null&amp;gt;(["c"]);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 21 Apr 2023 08:40:11 GMT</pubDate>
    <dc:creator>christian_barth</dc:creator>
    <dc:date>2023-04-21T08:40:11Z</dc:date>
    <item>
      <title>Default selecting an option with the Select component</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Default-selecting-an-option-with-the-Select-component/m-p/201212#M107</link>
      <description>&lt;P&gt;I'm using the &lt;A href="https://developer.dynatrace.com/reference/design-system/preview/forms/Select/" target="_self"&gt;Select component&lt;/A&gt; for an app, but although an option is selected by default the initial UI still says "choose an option".&lt;/P&gt;
&lt;P&gt;See attached screenshots for an additional explanation (screenshot 1 with the default state, screenshot 2 is in the 'clicked' state without any selection).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I'm looking for: Have 'Emerging Threats' already visible in the drop down when I'm loading the page as it's selected by default.&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2023 13:16:19 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Default-selecting-an-option-with-the-Select-component/m-p/201212#M107</guid>
      <dc:creator>3ene</dc:creator>
      <dc:date>2023-05-02T13:16:19Z</dc:date>
    </item>
    <item>
      <title>Re: Default selecting an option with the Select component</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Default-selecting-an-option-with-the-Select-component/m-p/201228#M109</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Select component provides a prop called &lt;STRONG&gt;defaultSelectedId&lt;/STRONG&gt;, which does exactly what you want to achieve.&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;&amp;lt;Select name="choice" defaultSelectedId={['option3']}&amp;gt;
  &amp;lt;SelectOption id="option1" value="first"&amp;gt;
    3coresec
  &amp;lt;/SelectOption&amp;gt;
  &amp;lt;SelectOption id="option2"&amp;gt;feodotracker&amp;lt;/SelectOption&amp;gt;
  &amp;lt;SelectOption id="option3"&amp;gt;emergingthreats&amp;lt;/SelectOption&amp;gt;
&amp;lt;/Select&amp;gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Dec 2022 08:16:58 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Default-selecting-an-option-with-the-Select-component/m-p/201228#M109</guid>
      <dc:creator>christian_barth</dc:creator>
      <dc:date>2022-12-30T08:16:58Z</dc:date>
    </item>
    <item>
      <title>Re: Default selecting an option with the Select component</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Default-selecting-an-option-with-the-Select-component/m-p/201283#M115</link>
      <description>&lt;P&gt;Thank you, Christian - is there any documentation which types defaultSelectedId allows? I get following error when I'm following your suggestion&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="3ene_0-1672654541767.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/9183iAAE3D34F4E636B6E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="3ene_0-1672654541767.png" alt="3ene_0-1672654541767.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just fyi: if I deleted the whole "defaultSelectedId=..." part, it works just fine (source as an attribute for selectedId works).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jan 2023 10:18:11 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Default-selecting-an-option-with-the-Select-component/m-p/201283#M115</guid>
      <dc:creator>3ene</dc:creator>
      <dc:date>2023-01-02T10:18:11Z</dc:date>
    </item>
    <item>
      <title>Re: Default selecting an option with the Select component</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Default-selecting-an-option-with-the-Select-component/m-p/201297#M116</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can find the documentation of the Props at the very bottom of the page:&amp;nbsp;&lt;A href="https://developer.dynatrace.com/reference/design-system/preview/forms/Select/#proptable" target="_blank" rel="noopener"&gt;https://developer.dynatrace.com/reference/design-system/preview/forms/Select/#proptable&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;In your case, it has to be an Array from type Key, which again is either a string or a number.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The easiest way to find this out is to check the type definitions directly in your IDE:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="christian_barth_0-1672663920598.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/9186iE202DA4E5FB9FF4E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="christian_barth_0-1672663920598.png" alt="christian_barth_0-1672663920598.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2023 13:16:50 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Default-selecting-an-option-with-the-Select-component/m-p/201297#M116</guid>
      <dc:creator>christian_barth</dc:creator>
      <dc:date>2023-05-02T13:16:50Z</dc:date>
    </item>
    <item>
      <title>Re: Default selecting an option with the Select component</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Default-selecting-an-option-with-the-Select-component/m-p/201311#M117</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;my selection array (&lt;EM&gt;sources&lt;/EM&gt;) is a string array, but it won't let me set the defaultID:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="3ene_3-1672670716824.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/9190i0BC8055DED6C8FA6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="3ene_3-1672670716824.png" alt="3ene_3-1672670716824.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Here is the whole form, maybe I'm making a rookie mistake:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="3ene_4-1672670754137.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/9191i92E91DD2982A6C95/image-size/medium?v=v2&amp;amp;px=400" role="button" title="3ene_4-1672670754137.png" alt="3ene_4-1672670754137.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I can't find a solution for my problem so far - even if I follow your suggestion with the [].&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="3ene_5-1672670906150.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/9192i7B51D712CE665537/image-size/medium?v=v2&amp;amp;px=400" role="button" title="3ene_5-1672670906150.png" alt="3ene_5-1672670906150.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Any other idea what I could try?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;React&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;useState&lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN&gt;SelectedKeys&lt;/SPAN&gt;&lt;SPAN&gt; | &lt;/SPAN&gt;&lt;SPAN&gt;null&lt;/SPAN&gt;&lt;SPAN&gt;&amp;gt;(&lt;/SPAN&gt;&lt;SPAN&gt;null&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jan 2023 14:49:03 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Default-selecting-an-option-with-the-Select-component/m-p/201311#M117</guid>
      <dc:creator>3ene</dc:creator>
      <dc:date>2023-01-02T14:49:03Z</dc:date>
    </item>
    <item>
      <title>Re: Default selecting an option with the Select component</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Default-selecting-an-option-with-the-Select-component/m-p/201314#M118</link>
      <description>&lt;P&gt;Solved it!&lt;/P&gt;&lt;P&gt;It might be worth to look into the data types that are needed for &lt;EM&gt;defaultSelectedId&lt;/EM&gt;, but here is how I could preselect a value:&lt;/P&gt;&lt;P&gt;1.) I run a useEffect that listens to my selection state (&lt;EM&gt;source&lt;/EM&gt; in my example). It also runs when the page is rendered initially.&lt;/P&gt;&lt;P&gt;2.) If that &lt;EM&gt;source&lt;/EM&gt; var is null (ie on the first render of the site), I set it to the desired preselected state, which preselects it. This way I can also query my result set right away.&lt;/P&gt;&lt;P&gt;I don't need &lt;EM&gt;defaultSelectedId&lt;/EM&gt;&amp;nbsp; at all - my select field looks like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="3ene_0-1672672370450.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/9193iB655C6035876F45E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="3ene_0-1672672370450.png" alt="3ene_0-1672672370450.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I don't now for sure, but it seems like defaultSelectedId is tricky to use. I couldn't find the correct type &lt;STRONG&gt;for hours.&lt;/STRONG&gt; I tried different casts, putting my array selection into brackets, etc. etc.. Documentation should be improved on that end.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jan 2023 15:16:48 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Default-selecting-an-option-with-the-Select-component/m-p/201314#M118</guid>
      <dc:creator>3ene</dc:creator>
      <dc:date>2023-01-02T15:16:48Z</dc:date>
    </item>
    <item>
      <title>Re: Default selecting an option with the Select component</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Default-selecting-an-option-with-the-Select-component/m-p/201317#M119</link>
      <description>&lt;P&gt;Another straightforward solution to your problem would be setting the default value of the state variable to your default selection value:&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;const [selected, setSelected] = useState&amp;lt;SelectedKeys | null&amp;gt;(["c"]);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 08:40:11 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Default-selecting-an-option-with-the-Select-component/m-p/201317#M119</guid>
      <dc:creator>christian_barth</dc:creator>
      <dc:date>2023-04-21T08:40:11Z</dc:date>
    </item>
  </channel>
</rss>

