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.

Toggling between two icons

See original GitHub issue

Hiya!

So I am working on a sortable table and using the sort/sort-up/sort-down icons

dec-21-2017 13-41-04

But try as I might, I can’t get the icon components to change after the first instance. Almost like the DOM node is being rendered but not cleared when the icon should change.

in the template:

  <icon icon="sort" v-if="sort.segment !== 'completed_at'"></icon>
  <icon :icon="sortIconDirection" v-else></icon>

and I have a computed value:

    sortIconDirection() {
      return this.sort.direction === 'asc' ? 'sort-up' : 'sort-down';
    },

And I can see the computed value correctly toggling in state, but the icon doesn’t switch out. I’ve also tried adding another icon component with a set of v-if/else-if conditions and I can’t get it to quite work. (BTW, icon is just what I named the imported vue-fontawesome component as, migrating over from Justineo/vue-awesome)

I hope this makes sense! I’ve been up for a long time ha. If needed, I can try to build a reduced test case if you’re unable to reproduce.

Thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:28 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
OriginalEXEcommented, Jan 14, 2018

Hmm, I am seeing the same issue, I found that adding :key="JSON.stringify(sortIconDirection)" to your icon element solves this, but I am interested in understanding why it’s needed at all.

1reaction
CmdrSharpcommented, Mar 15, 2018

@robmadole Good news! I both re-produced it, and found a work-around. It seems the shorthand exits for the font-awesome-icon causes this behavior. When closing that tag out normally instead, v-if cases behave like they should!

Example: https://codesandbox.io/s/y0ky64p1z

Not sure if I’m missing anything obvious here, but every single example from the repo readme shows using shorthand termination - so either the documentation should be updated, or this should work! 😃

Hope it helps!

EDIT: I do realize that self-closing tags are a thing of XHTML, which is why it may be failing - but again, since the documentation displays them, it’d make sense that they work. If it is a bug, please let me know - otherwise, I’ll gladly make a PR to update the readme, reflecting proper use.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to toggle between 2 icons - javascript - Stack Overflow
I have to toggle between two icons based on ...
Read more >
How to toggle between two icons without buttons using boot ...
Approach: The approach is to simply add an “on click” event listener to both of the icons and toggle the CSS classes of...
Read more >
How To Toggle Like and Dislike - W3Schools
Toggle between a like/dislike button with CSS and JavaScript. Click on the icon to toggle between thumbs-up and thumbs-down (like/dislike): ...
Read more >
Switch Icons in CSS and Javascript - CodyHouse
The Switch Icon component is used to create a transition between two icons. You can use any icon you want. In the demo...
Read more >
How to toggle images/icons using React Hooks for beginners ...
On this occasion, I'm going to show you how to toggle between two images/icons (stars). It's going to be perceived as if one...
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