React bootstrap onclick list-group-item highlight the item/ active












0















I have 2 panel with list group on each panel. I am using bootstrap.



Issue:
onclick first list-group-item on panel 1 it changing style = "success", but when I click on the second list-group-item on panel 1 style change to "success" but not changing the first list-group-item style to default (style = "").



onclick on list-group-item it should change style or active or change the background color. Highlight the selected item and remove it when click on another item on the respective panel.

Alternative <ListGroupItem href="#" active>



my code: Code










share|improve this question





























    0















    I have 2 panel with list group on each panel. I am using bootstrap.



    Issue:
    onclick first list-group-item on panel 1 it changing style = "success", but when I click on the second list-group-item on panel 1 style change to "success" but not changing the first list-group-item style to default (style = "").



    onclick on list-group-item it should change style or active or change the background color. Highlight the selected item and remove it when click on another item on the respective panel.

    Alternative <ListGroupItem href="#" active>



    my code: Code










    share|improve this question



























      0












      0








      0








      I have 2 panel with list group on each panel. I am using bootstrap.



      Issue:
      onclick first list-group-item on panel 1 it changing style = "success", but when I click on the second list-group-item on panel 1 style change to "success" but not changing the first list-group-item style to default (style = "").



      onclick on list-group-item it should change style or active or change the background color. Highlight the selected item and remove it when click on another item on the respective panel.

      Alternative <ListGroupItem href="#" active>



      my code: Code










      share|improve this question
















      I have 2 panel with list group on each panel. I am using bootstrap.



      Issue:
      onclick first list-group-item on panel 1 it changing style = "success", but when I click on the second list-group-item on panel 1 style change to "success" but not changing the first list-group-item style to default (style = "").



      onclick on list-group-item it should change style or active or change the background color. Highlight the selected item and remove it when click on another item on the respective panel.

      Alternative <ListGroupItem href="#" active>



      my code: Code







      javascript reactjs react-bootstrap






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 1 at 14:34









      Cœur

      18.7k9110150




      18.7k9110150










      asked Sep 4 '18 at 6:31









      contact dummycontact dummy

      1639




      1639
























          1 Answer
          1






          active

          oldest

          votes


















          1














          On onSelectDevice function your setting card.style = "success"; to both buttons A and B.



          But your not resetting the old style to empty when clicking on B.



          either you can do like @Guillermo Quiros solution or you can setState again this.state.cards like below :



          let showPropContainer = this.state.cards.slice() or [...this.state.cards];
          let cards = showPropContainer.map((val, index) => {
          val.esn === card.esn ? val.style="success" : val.style=""
          return val;
          });
          this.setState({ selectedCard: card , cards})


          Full solution available here






          share|improve this answer
























          • Thank you but I found Guillermo Quiros bit easy. I will go through your code and understand.

            – contact dummy
            Sep 4 '18 at 7:05











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52160077%2freact-bootstrap-onclick-list-group-item-highlight-the-item-active%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          On onSelectDevice function your setting card.style = "success"; to both buttons A and B.



          But your not resetting the old style to empty when clicking on B.



          either you can do like @Guillermo Quiros solution or you can setState again this.state.cards like below :



          let showPropContainer = this.state.cards.slice() or [...this.state.cards];
          let cards = showPropContainer.map((val, index) => {
          val.esn === card.esn ? val.style="success" : val.style=""
          return val;
          });
          this.setState({ selectedCard: card , cards})


          Full solution available here






          share|improve this answer
























          • Thank you but I found Guillermo Quiros bit easy. I will go through your code and understand.

            – contact dummy
            Sep 4 '18 at 7:05
















          1














          On onSelectDevice function your setting card.style = "success"; to both buttons A and B.



          But your not resetting the old style to empty when clicking on B.



          either you can do like @Guillermo Quiros solution or you can setState again this.state.cards like below :



          let showPropContainer = this.state.cards.slice() or [...this.state.cards];
          let cards = showPropContainer.map((val, index) => {
          val.esn === card.esn ? val.style="success" : val.style=""
          return val;
          });
          this.setState({ selectedCard: card , cards})


          Full solution available here






          share|improve this answer
























          • Thank you but I found Guillermo Quiros bit easy. I will go through your code and understand.

            – contact dummy
            Sep 4 '18 at 7:05














          1












          1








          1







          On onSelectDevice function your setting card.style = "success"; to both buttons A and B.



          But your not resetting the old style to empty when clicking on B.



          either you can do like @Guillermo Quiros solution or you can setState again this.state.cards like below :



          let showPropContainer = this.state.cards.slice() or [...this.state.cards];
          let cards = showPropContainer.map((val, index) => {
          val.esn === card.esn ? val.style="success" : val.style=""
          return val;
          });
          this.setState({ selectedCard: card , cards})


          Full solution available here






          share|improve this answer













          On onSelectDevice function your setting card.style = "success"; to both buttons A and B.



          But your not resetting the old style to empty when clicking on B.



          either you can do like @Guillermo Quiros solution or you can setState again this.state.cards like below :



          let showPropContainer = this.state.cards.slice() or [...this.state.cards];
          let cards = showPropContainer.map((val, index) => {
          val.esn === card.esn ? val.style="success" : val.style=""
          return val;
          });
          this.setState({ selectedCard: card , cards})


          Full solution available here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Sep 4 '18 at 7:01









          JayavelJayavel

          1,72111125




          1,72111125













          • Thank you but I found Guillermo Quiros bit easy. I will go through your code and understand.

            – contact dummy
            Sep 4 '18 at 7:05



















          • Thank you but I found Guillermo Quiros bit easy. I will go through your code and understand.

            – contact dummy
            Sep 4 '18 at 7:05

















          Thank you but I found Guillermo Quiros bit easy. I will go through your code and understand.

          – contact dummy
          Sep 4 '18 at 7:05





          Thank you but I found Guillermo Quiros bit easy. I will go through your code and understand.

          – contact dummy
          Sep 4 '18 at 7:05




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52160077%2freact-bootstrap-onclick-list-group-item-highlight-the-item-active%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          'app-layout' is not a known element: how to share Component with different Modules

          android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

          WPF add header to Image with URL pettitions [duplicate]