<?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 Deselected value list item still display as selected in Calcite Design System Questions</title>
    <link>https://community.esri.com/t5/calcite-design-system-questions/deselected-value-list-item-still-display-as/m-p/1310408#M449</link>
    <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;I've been trying to make use of value list in the code below.&lt;/P&gt;&lt;P&gt;The issue is that the focus rectangle still display around an item when it gets deselected.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="utf-8" /&amp;gt;
    &amp;lt;meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no"/&amp;gt;

    &amp;lt;title&amp;gt;V1 - Workaround : Deselecting a value list item&amp;lt;/title&amp;gt;

    &amp;lt;script src="https://js.arcgis.com/4.25/"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.25/esri/themes/light/main.css"/&amp;gt;

    &amp;lt;script type="module" src="https://js.arcgis.com/calcite-components/1.0.0-beta.99/calcite.esm.js"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;link rel="stylesheet" type="text/css" href=https://js.arcgis.com/calcite-components/1.0.0-beta.99/calcite.css /&amp;gt;
  &amp;lt;/head&amp;gt;

  &amp;lt;body&amp;gt;
    &amp;lt;calcite-shell class="calcite-tutorial"&amp;gt;
      &amp;lt;calcite-shell-panel slot="panel-end"&amp;gt;
        &amp;lt;calcite-panel heading="Point list"&amp;gt;
          &amp;lt;calcite-value-list id="point-list"&amp;gt;
            &amp;lt;calcite-value-list-item label="point 1" value="point_1" description="NOT Selected"&amp;gt;&amp;lt;/calcite-value-list-item&amp;gt;
            &amp;lt;calcite-value-list-item label="point 2" value="point_2" description="NOT Selected"&amp;gt;&amp;lt;/calcite-value-list-item&amp;gt;
            &amp;lt;calcite-value-list-item label="point 3" value="point_3" description="NOT Selected"&amp;gt;&amp;lt;/calcite-value-list-item&amp;gt;
          &amp;lt;/calcite-value-list&amp;gt;
        &amp;lt;/calcite-panel&amp;gt;
      &amp;lt;/calcite-shell-panel&amp;gt;
    &amp;lt;/calcite-shell&amp;gt;
    
    &amp;lt;script&amp;gt;
      "use strict";

      const listNode = document.getElementById("point-list")

      // Cannot use the event listener below because nothing's fired when already-selected item is clicked          
      //listNode.addEventListener("calciteListChange", onListClickHandler)

      listNode.addEventListener("click", onListClickHandler)

      const currentSelectedListItem = (function(){
        let currentItemValue
        return {
          is_same: function(selectedItemValue) {
            if (currentItemValue != selectedItemValue) {
              currentItemValue = selectedItemValue
              return false
            }
            else {
              return true
            }
          },
          reset: function() {
            currentItemValue = null
          }
        }
      })();

      function onListClickHandler(event) {
        const target = event.target
        const targetId = target.value

        if (currentSelectedListItem.is_same(targetId)) {
          console.log("already selected")
          target.selected = false;
          currentSelectedListItem.reset();
          // Do some stuff on map
          
          // Test 1 (FAILS)
          //target.toggleSelected()

          // Test 2 (FAILS)
          //target.removeAttribute("selected")
       
          // Test 4 (FAILS)
          //Array.from(listNode.childNodes).forEach(item =&amp;gt; item.selected = false)

          // Test 5 (FAILS)
          //const listItems = listNode.querySelectorAll("calcite-value-list-item")
          //listItems.forEach(item =&amp;gt; item.selected = false)
        }
        else {
          console.log("new selection")
          // Do some stuff on map
        }
        
        // Debug test : updating the descriptions to show the selected state of each list item.
        for(let listItem of event.target.parentElement.children) {
          listItem.description = listItem.selected ? "Selected" : "NOT Selected";
        }
        //console.log(event.target.parentElement.children)
      }
    &amp;lt;/script&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you help me please ?&lt;/P&gt;</description>
    <pubDate>Fri, 21 Jul 2023 14:56:36 GMT</pubDate>
    <dc:creator>OlivierLefevre</dc:creator>
    <dc:date>2023-07-21T14:56:36Z</dc:date>
    <item>
      <title>Deselected value list item still display as selected</title>
      <link>https://community.esri.com/t5/calcite-design-system-questions/deselected-value-list-item-still-display-as/m-p/1310408#M449</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;I've been trying to make use of value list in the code below.&lt;/P&gt;&lt;P&gt;The issue is that the focus rectangle still display around an item when it gets deselected.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="utf-8" /&amp;gt;
    &amp;lt;meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no"/&amp;gt;

    &amp;lt;title&amp;gt;V1 - Workaround : Deselecting a value list item&amp;lt;/title&amp;gt;

    &amp;lt;script src="https://js.arcgis.com/4.25/"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.25/esri/themes/light/main.css"/&amp;gt;

    &amp;lt;script type="module" src="https://js.arcgis.com/calcite-components/1.0.0-beta.99/calcite.esm.js"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;link rel="stylesheet" type="text/css" href=https://js.arcgis.com/calcite-components/1.0.0-beta.99/calcite.css /&amp;gt;
  &amp;lt;/head&amp;gt;

  &amp;lt;body&amp;gt;
    &amp;lt;calcite-shell class="calcite-tutorial"&amp;gt;
      &amp;lt;calcite-shell-panel slot="panel-end"&amp;gt;
        &amp;lt;calcite-panel heading="Point list"&amp;gt;
          &amp;lt;calcite-value-list id="point-list"&amp;gt;
            &amp;lt;calcite-value-list-item label="point 1" value="point_1" description="NOT Selected"&amp;gt;&amp;lt;/calcite-value-list-item&amp;gt;
            &amp;lt;calcite-value-list-item label="point 2" value="point_2" description="NOT Selected"&amp;gt;&amp;lt;/calcite-value-list-item&amp;gt;
            &amp;lt;calcite-value-list-item label="point 3" value="point_3" description="NOT Selected"&amp;gt;&amp;lt;/calcite-value-list-item&amp;gt;
          &amp;lt;/calcite-value-list&amp;gt;
        &amp;lt;/calcite-panel&amp;gt;
      &amp;lt;/calcite-shell-panel&amp;gt;
    &amp;lt;/calcite-shell&amp;gt;
    
    &amp;lt;script&amp;gt;
      "use strict";

      const listNode = document.getElementById("point-list")

      // Cannot use the event listener below because nothing's fired when already-selected item is clicked          
      //listNode.addEventListener("calciteListChange", onListClickHandler)

      listNode.addEventListener("click", onListClickHandler)

      const currentSelectedListItem = (function(){
        let currentItemValue
        return {
          is_same: function(selectedItemValue) {
            if (currentItemValue != selectedItemValue) {
              currentItemValue = selectedItemValue
              return false
            }
            else {
              return true
            }
          },
          reset: function() {
            currentItemValue = null
          }
        }
      })();

      function onListClickHandler(event) {
        const target = event.target
        const targetId = target.value

        if (currentSelectedListItem.is_same(targetId)) {
          console.log("already selected")
          target.selected = false;
          currentSelectedListItem.reset();
          // Do some stuff on map
          
          // Test 1 (FAILS)
          //target.toggleSelected()

          // Test 2 (FAILS)
          //target.removeAttribute("selected")
       
          // Test 4 (FAILS)
          //Array.from(listNode.childNodes).forEach(item =&amp;gt; item.selected = false)

          // Test 5 (FAILS)
          //const listItems = listNode.querySelectorAll("calcite-value-list-item")
          //listItems.forEach(item =&amp;gt; item.selected = false)
        }
        else {
          console.log("new selection")
          // Do some stuff on map
        }
        
        // Debug test : updating the descriptions to show the selected state of each list item.
        for(let listItem of event.target.parentElement.children) {
          listItem.description = listItem.selected ? "Selected" : "NOT Selected";
        }
        //console.log(event.target.parentElement.children)
      }
    &amp;lt;/script&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you help me please ?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2023 14:56:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/calcite-design-system-questions/deselected-value-list-item-still-display-as/m-p/1310408#M449</guid>
      <dc:creator>OlivierLefevre</dc:creator>
      <dc:date>2023-07-21T14:56:36Z</dc:date>
    </item>
    <item>
      <title>Re: Deselected value list item still display as selected</title>
      <link>https://community.esri.com/t5/calcite-design-system-questions/deselected-value-list-item-still-display-as/m-p/1310698#M452</link>
      <description>&lt;P&gt;Calcite aims to support accessibility, which includes focus states for all audiences, whether it be selecting via keyboard or mouse. As a result the focus state will be present even if the component's state changes to accommodate low vision and more users.&lt;/P&gt;
&lt;P&gt;Of note, the Value List component is deprecated and it's end of life is approaching once full functionality is achieved in the updated &lt;A href="https://developers.arcgis.com/calcite-design-system/components/list/" target="_blank" rel="noopener"&gt;List&lt;/A&gt; component. More information on the parity can be found in the &lt;A href="https://github.com/Esri/calcite-design-system/issues/6430" target="_blank" rel="noopener"&gt;GitHub epic&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;A similar implementation can be achieved with List in the latest Calcite version, 1.4.3, where while focus remains on the List Item upon selection/de-selection, a selection is also toggled on/off to provide more context to users: &lt;A href="https://codepen.io/geospatialem/pen/JjeBXwp" target="_blank" rel="noopener"&gt;https://codepen.io/geospatialem/pen/JjeBXwp&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;There is also an enhancement request to modify the selection states in the near future with #&lt;A href="https://github.com/Esri/calcite-design-system/issues/7106" target="_blank" rel="noopener"&gt;7106&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2023 21:51:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/calcite-design-system-questions/deselected-value-list-item-still-display-as/m-p/1310698#M452</guid>
      <dc:creator>KittyHurley</dc:creator>
      <dc:date>2023-07-21T21:51:02Z</dc:date>
    </item>
  </channel>
</rss>

