<?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: How to reset calcite-dropdown to a default calcite-dropdown-item in Calcite Design System Questions</title>
    <link>https://community.esri.com/t5/calcite-design-system-questions/how-to-reset-calcite-dropdown-to-a-default-calcite/m-p/1223581#M259</link>
    <description>&lt;P&gt;Ok. Thank you for the suggestion and example, Kitty. I wasn't able to get the Codepen example to reset. But that's Ok because I want to stick with the design I have already built. Removing the component and rebuilding it on a reset is working out for me.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="GregoryBologna_0-1666213215427.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/54000i60496E8C1DF77560/image-size/medium?v=v2&amp;amp;px=400" role="button" title="GregoryBologna_0-1666213215427.png" alt="GregoryBologna_0-1666213215427.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 19 Oct 2022 21:04:44 GMT</pubDate>
    <dc:creator>GregoryBologna</dc:creator>
    <dc:date>2022-10-19T21:04:44Z</dc:date>
    <item>
      <title>How to reset calcite-dropdown to a default calcite-dropdown-item</title>
      <link>https://community.esri.com/t5/calcite-design-system-questions/how-to-reset-calcite-dropdown-to-a-default-calcite/m-p/1223402#M257</link>
      <description>&lt;P&gt;I want to reset the calcite-dropdown-item to a specific default item anytime a reset of the container is clicked. My code to reset it doesn't work as well as I had hoped. My workflow is to first unset the current selected calcite-dropdown-item and then set the default calcite-dropdown-item. I had to use dispatchEvent to set properties for other elements, but doing this was somewhat incomplete. My solution, which works, is to just remove the calcite-dropdown and rebuild it.&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="container" style="width: 428px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/53958i1A31FDCDDF99549C/image-size/large?v=v2&amp;amp;px=999" role="button" title="2022-10-19_11-58-19.png" alt="container" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;container&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;&lt;LI-CODE lang="javascript"&gt;async function resetBufferUnit() {
	try {
		// remove calcite-dropdown and recreate
		document.querySelector('#pao-buffer-unit').remove();
		let results = await buildBufferUnitsOption();
		let p = document.getElementById('pao-buffer-slider-block');
		if (p) p.insertBefore(results, p.firstChild);

		// doesn't work right
		// get current active unit and reset to default unit feet
		/* let el = document.querySelectorAll('#pao-buffer-unit-group1&amp;gt;calcite-dropdown-item[active]');
		 if (el[0]?.id !== 'pao-unit-feet') {
			 el[0].active = false;
			 el[0].removeAttribute('active');
			 el[0].removeAttribute('selected');
			 el[0].setAttribute('aria-checked', 'false');

			// set default pao-unit-feet
			 el = document.querySelectorAll('#pao-buffer-unit-group1&amp;gt;calcite-dropdown-item#pao-unit-feet');
			 if (el) {
				 el[0].active = true;
				 el[0].setAttribute('active', '');
				 el[0].setAttribute('selected', '');
				 el[0].setAttribute('aria-checked', 'true');

				 const e = new Event('calciteDropdownSelect');
				 el = document.getElementById('pao-buffer-unit');
				 el.dispatchEvent(e);
			}
		}
		*/
	} catch (err) {
		console.log(err);
	}
} // end

function buildBufferUnitsOption() {
	return new Promise((resolve) =&amp;gt; {
		let opt = document.createElement('calcite-dropdown');
		opt.setAttribute('id', 'pao-buffer-unit');
		opt.setAttribute('overlay-positioning', 'fixed');
		opt.setAttribute('placement', 'bottom-start');
		opt.setAttribute('type', 'click');		
		opt.setAttribute('scale', 'm');
		opt.style.whiteSpace = 'nowrap';
		opt.addEventListener('calciteDropdownSelect', getBufferUnitType);

		let btn = document.createElement('calcite-button');
		btn.setAttribute('slot', 'dropdown-trigger');
		btn.setAttribute('id', 'pao-buffer-unit-button');
		btn.setAttribute('scale', 'm');
		opt.appendChild(btn);

		let grp = document.createElement('calcite-dropdown-group');
		grp.setAttribute('id', 'pao-buffer-unit-group1');
		grp.setAttribute('selection-mode', 'single');

		// Feet
		let opt_item = document.createElement('calcite-dropdown-item');
		opt_item.setAttribute('id', 'pao-unit-feet');
		opt_item.setAttribute('active', '');
		opt_item.setAttribute('data-unit-abrv', 'ft');
		opt_item.innerHTML = 'Feet';
		grp.appendChild(opt_item);
		unitType = 'feet'; // init to default feet

		// Yards
		opt_item = document.createElement('calcite-dropdown-item');
		opt_item.setAttribute('id', 'pao-unit-yards');
		opt_item.setAttribute('data-unit-abrv', 'yds');
		opt_item.innerHTML = 'Yards';
		grp.appendChild(opt_item);

		// Kilometers
		opt_item = document.createElement('calcite-dropdown-item');
		opt_item.setAttribute('id', 'pao-unit-kilometers');
		opt_item.setAttribute('data-unit-abrv', 'km');
		opt_item.innerHTML = 'Kilometers';
		grp.appendChild(opt_item);

		// Meters
		opt_item = document.createElement('calcite-dropdown-item');
		opt_item.setAttribute('id', 'pao-unit-meters');
		opt_item.setAttribute('data-unit-abrv', 'm');
		opt_item.innerHTML = 'Meters';
		grp.appendChild(opt_item);

		// Miles. (enabled based on parcel density determined by specification)
		opt_item = document.createElement('calcite-dropdown-item');
		opt_item.setAttribute('id', 'pao-unit-miles');
		opt_item.setAttribute('data-unit-abrv', 'mi');

		opt_item.innerHTML = 'Miles';
		grp.appendChild(opt_item);

		opt.appendChild(grp);
		resolve(opt);
	});
} // end&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2022 16:08:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/calcite-design-system-questions/how-to-reset-calcite-dropdown-to-a-default-calcite/m-p/1223402#M257</guid>
      <dc:creator>GregoryBologna</dc:creator>
      <dc:date>2022-10-19T16:08:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to reset calcite-dropdown to a default calcite-dropdown-item</title>
      <link>https://community.esri.com/t5/calcite-design-system-questions/how-to-reset-calcite-dropdown-to-a-default-calcite/m-p/1223515#M258</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/193359"&gt;@GregoryBologna&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;The&amp;nbsp;&lt;A href="https://developers.arcgis.com/calcite-design-system/components/select/" target="_blank" rel="noopener"&gt;Select component&lt;/A&gt; might be a better fit for the use case based on the sample provided above. The component works well for selections, and in particular with form-based selections.&lt;/P&gt;&lt;P&gt;If that seems in line with the use case, here's a&amp;nbsp;&lt;A href="https://codepen.io/geospatialem/pen/jOxjWLJ" target="_blank" rel="noopener"&gt;Codepen example&lt;/A&gt; using the Select and &lt;A href="https://developers.arcgis.com/calcite-design-system/components/option/" target="_blank" rel="noopener"&gt;Option&lt;/A&gt; components.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2022 19:03:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/calcite-design-system-questions/how-to-reset-calcite-dropdown-to-a-default-calcite/m-p/1223515#M258</guid>
      <dc:creator>KittyHurley</dc:creator>
      <dc:date>2022-10-19T19:03:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to reset calcite-dropdown to a default calcite-dropdown-item</title>
      <link>https://community.esri.com/t5/calcite-design-system-questions/how-to-reset-calcite-dropdown-to-a-default-calcite/m-p/1223581#M259</link>
      <description>&lt;P&gt;Ok. Thank you for the suggestion and example, Kitty. I wasn't able to get the Codepen example to reset. But that's Ok because I want to stick with the design I have already built. Removing the component and rebuilding it on a reset is working out for me.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="GregoryBologna_0-1666213215427.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/54000i60496E8C1DF77560/image-size/medium?v=v2&amp;amp;px=400" role="button" title="GregoryBologna_0-1666213215427.png" alt="GregoryBologna_0-1666213215427.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2022 21:04:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/calcite-design-system-questions/how-to-reset-calcite-dropdown-to-a-default-calcite/m-p/1223581#M259</guid>
      <dc:creator>GregoryBologna</dc:creator>
      <dc:date>2022-10-19T21:04:44Z</dc:date>
    </item>
  </channel>
</rss>

