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

bug: Creating a modal component without resorting to customElements #24379

Closed
4 of 6 tasks
raymondboswel opened this issue Dec 13, 2021 · 10 comments
Closed
4 of 6 tasks
Labels

Comments

@raymondboswel
Copy link

Prerequisites

Ionic Framework Version

  • v4.x
  • v5.x
  • v6.x

Current Behavior

I'm currently using Ionic in a Svelte project. According to the docs, when using Ionic without one of the standard framework bindings, you ustom element. This is proving to be problematic, since my global styles / tailwind classes are not applied in the custom element.

Expected Behavior

Having used @ionic/angular in quite a few projects it definitely didn't feel like the modal components were being converted to customElements behind the scenes, so I assume there's another mechanism that can be used in addition to creating custom elements?

Steps to Reproduce

Create blank project with Svelte or just vanillaJS and use modalController in application

Code Reproduction URL

No response

Ionic Info

No response

Additional Information

No response

@ionitron-bot ionitron-bot bot added the triage label Dec 13, 2021
@liamdebeasi liamdebeasi self-assigned this Dec 13, 2021
@liamdebeasi
Copy link
Contributor

Thanks for the issue. Can you try slotting your content in directly inside of ion-modal?

<ion-modal is-open="true">
  <!-- put your content here -->
</ion-modal>

This should let you pass in content directly without having to use a custom element.

For Ionic Angular projects, we have a utility that interfaces with Angular so you can use Angular components. Since we do not have a Svelte integration, this utility does not exist for Svelte projects.

@liamdebeasi liamdebeasi added the needs: reply the issue needs a response from the user label Dec 13, 2021
@liamdebeasi liamdebeasi removed their assignment Dec 13, 2021
@ionitron-bot ionitron-bot bot removed the triage label Dec 13, 2021
@raymondboswel
Copy link
Author

raymondboswel commented Dec 13, 2021

Hi @liamdebeasi, thank you for the suggestion. I have tried it, but there seems to be some layout issues (the content at the bottom of the modal extends below the screen, also leave animation of modal is a bit weird). I have in the mean time come across a solution which I have had to slightly adapt, but seems to work well, so I'll leave that here as an alternative:

//Unused component variable to force component import at function call
export const IonicShowModal = async (
  selector: string,
  component: new (...args: any) => SvelteComponent,
  componentProps: any
) => {
  
  const modal = await modalController.create({
    component: selector,
    componentProps,
  });
  await modal.present();

  //TODO: Consider what should happen if more than 1 tag found...
  let elem = document.getElementsByTagName(selector)[0];  
  
  let svelteComponent = new component({ target: elem, props: componentProps, });

  let res = await modal.onWillDismiss();

  svelteComponent.$destroy();
  elem.remove();

  return res;
  
};

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels Dec 13, 2021
@liamdebeasi
Copy link
Contributor

Can you reproduce the layout issues in a sample app?

@liamdebeasi liamdebeasi added the needs: reply the issue needs a response from the user label Dec 13, 2021
@ionitron-bot ionitron-bot bot removed the triage label Dec 13, 2021
@raymondboswel
Copy link
Author

I'm sure I could. I'll create a reproduction in the AM 👍

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels Dec 13, 2021
@liamdebeasi
Copy link
Contributor

Thank you!

@liamdebeasi liamdebeasi added the needs: reply the issue needs a response from the user label Dec 13, 2021
@ionitron-bot ionitron-bot bot removed the triage label Dec 13, 2021
@raymondboswel
Copy link
Author

I created a reproduction repo here: https://github.com/raymondboswel/ionic-modal-reproduction. There's a note and usage instructions in the README. Thanks 🍻

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels Dec 14, 2021
@liamdebeasi
Copy link
Contributor

The sizing issue seems to be related to the margins you have applied to article. Wrapping the article in a <div class="ion-page"> seems to do the trick.

With the framework bindings we do this for you. Can you try that and let me know if it resolves the issue?

@liamdebeasi liamdebeasi added the needs: reply the issue needs a response from the user label Dec 16, 2021
@ionitron-bot ionitron-bot bot removed the triage label Dec 16, 2021
@raymondboswel
Copy link
Author

Hi @liamdebeasi, that works! We can close this one out. Thanks a million 👍

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels Dec 17, 2021
@averyjohnston
Copy link
Contributor

Glad to hear this is resolved! I'll close this. Thanks for using Ionic!

@ionitron-bot
Copy link

ionitron-bot bot commented Jan 16, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Jan 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants