Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change update to computed #1091

Conversation

davidnixon
Copy link
Collaborator

Closes #

The side nav with icon does not work properly if the side nav is hidden with v-if and then later shown
https://ihzer.csb.app/
image

Force an update to show icons
image

Changelog

M packages/core/src/components/cv-ui-shell/cv-side-nav-link.vue

@netlify
Copy link

netlify bot commented Dec 7, 2020

Deploy preview for carbon-components-vue ready!

Built with commit f2a0238

https://deploy-preview-1091--carbon-components-vue.netlify.app

updated() {
this.hasNavIcon = !!this.$slots['nav-icon'];
computed: {
hasNavIcon() {
Copy link
Member

@lee-chase lee-chase Dec 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slots are not reactive so I am not sure this will work. Generally, I tend to use the following pattern. Does this work for you?

data(): {
  return {hasSlotX: false};
},
mounted() {
  this.checkSlots();
},
updated() {
  this.checkSlots();
},
methods: {
  checkSlots() {
    this.hasSlotX = !!this.$slots['slot-x'];
  },
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the slots not being reactive is the core issue.

Both the computed version and your version with the updated and mounted both work.

Testing with my use case, I added some logging and I can see that adding the check to the mounted function fixes the issue. The update function is not called.

I can also see that if I use the computed version, the hasNavIcon() function is called during the mount process and update process.

LMK if you want me to change this to use the updated/mounted pattern above. I didn't look at the other file cv-side-nav* files but now that I am looking I see they are all using that updated/mounted pattern so probably better that they are all the same.

@lee-chase
Copy link
Member

Closing in favour of #1902

@lee-chase lee-chase closed this Dec 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants