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

Modal component doesn't work twice #497

Closed
StCyr opened this issue Jul 21, 2019 · 12 comments · Fixed by #3769
Closed

Modal component doesn't work twice #497

StCyr opened this issue Jul 21, 2019 · 12 comments · Fixed by #3769
Labels
1. to develop Accepted and waiting to be taken care of bug Something isn't working feature: modal Related to the modal component

Comments

@StCyr
Copy link
Contributor

StCyr commented Jul 21, 2019

Hi,

I'm using the Modal component to display attached images in the "social" application.

For some reasons, images aren't displayed when the user tries to display them a second time: the Modal component shows a black screen with only the "x" icon in the top-right corner.

Do i use the component wrong, or is it some kind of limitation?

Thanks for the help,

Cyrille

Steps to reproduce the issue

  1. Install the social app
  2. have a timeline containing posts with attachments
  3. click on a thumbnail to display an attachment
  4. Confirm the image is shown properly using the Modal component
  5. Close the Modal
  6. Click the thumbnail again
  7. Confirm that the Modal component only displays a black screen

Additional info

Here's where I use the component:

https://github.com/nextcloud/social/blob/master/src/components/PostAttachment.vue

@skjnldsv
Copy link
Contributor

Any error in logs?

@skjnldsv skjnldsv added bug Something isn't working feature: modal Related to the modal component labels Jul 22, 2019
@juliushaertl
Copy link
Contributor

Hm, I can reproduce that with the modal example code in https://nextcloud-vue-components.netlify.com/#/Components?id=modal

Seems this is cause by using v-show to trigger the modal, switching to v-if fixes it.

@skjnldsv Any idea why this is an issue?

@skjnldsv
Copy link
Contributor

skjnldsv commented Jul 22, 2019

I would say because we do not detect the modal hide/show other than on mounted?
https://github.com/nextcloud/nextcloud-vue/blob/fe4e53f6b1335422571dca579149c7cee2078857/src/components/Modal/Modal.vue#L278-L279

@StCyr
Copy link
Contributor Author

StCyr commented Jul 22, 2019

Seems this is cause by using v-show to trigger the modal, switching to v-if fixes it.

It seems that I can't use $refs anymore when using v-if

        <masonry>
                <div v-for="(item, index) in attachments" :key="index">
                        <img :src="OC.generateUrl('/apps/social/document/get/resized?id=' + item.id)" @click="showModal(index)">
                </div>
                <modal v-if="modal" :has-previous="current > 0" :has-next="current < (attachments.length - 1)"
                        size="full" @close="closeModal" @previous="showPrevious"
                        @next="showNext">
                        <div class="modal__content">
                                <canvas ref="modalCanvas" />
                        </div>
                </modal>
        </masonry>

I'm suddenly getting TypeError: "canvas is undefined" when I click on a masonry component after changing v-show to v-if...

@skjnldsv
Copy link
Contributor

TypeError: "canvas is undefined"

Well you named your ref "modalCanvas" not "canvas" :p

@StCyr
Copy link
Contributor Author

StCyr commented Jul 22, 2019

no, that's not the issue, I've:

                       var canvas = this.$refs.modalCanvas
                        var ctx = canvas.getContext('2d')

It seems to be caused by the fact that v-if doesn't create the DOM element unless needed while v-show always creates it and just toggles the display CSS property.

@skjnldsv
Copy link
Contributor

Ah yes indeed, you cannot use an item inside if v-if is false.

@StCyr
Copy link
Contributor Author

StCyr commented Jul 22, 2019

and $refs is not reactive :-(

@skjnldsv
Copy link
Contributor

@StCyr I think this needs to be fixed from the modal component, not yours :)

@skjnldsv skjnldsv added the 1. to develop Accepted and waiting to be taken care of label Jul 22, 2019
@StCyr
Copy link
Contributor Author

StCyr commented Sep 11, 2019

I've studied more what's happening when opening/closing a modal:

1- When opening a page with a modal component, the modal component's element with class modal-mask has a style "display: none;" and its children element with class modal-wrapper has a style "";
2- When opening the modal component, the element with class modal-mask remove its style "display: none;" effectively displaying the modal;
3- When closing the modal component, the element with class modal-mask sets its style back to "display: none;" and also sets the style of its modal-wrapper children element to "display:none;"
4- When opening the modal component again, the element with class modal-mask remove its style "display: none;" but not the one of its modal-wrapper children element

This explains why the modal component's content is show only once.

Now, I have no idea how to fix this.

@skjnldsv
Copy link
Contributor

I'll try to take a look this week if I have time :)
Use v-if while you can. We can sit down at the conference and try to see how we can fix this 😉

@StCyr
Copy link
Contributor Author

StCyr commented Sep 12, 2019

I'll try to take a look this week if I have time :)
Use v-if while you can. We can sit down at the conference and try to see how we can fix this 😉

yeah, using v-if solves the issue.

Hope to see you there :-)

StCyr added a commit to nextcloud/social that referenced this issue Sep 12, 2019
ArtificialOwl pushed a commit to nextcloud/social that referenced this issue Sep 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1. to develop Accepted and waiting to be taken care of bug Something isn't working feature: modal Related to the modal component
Projects
None yet
3 participants