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

Ionic 4 Modal not appearing with transparent background #18589

Open
AshishSanu opened this issue Jun 21, 2019 · 11 comments
Open

Ionic 4 Modal not appearing with transparent background #18589

AshishSanu opened this issue Jun 21, 2019 · 11 comments
Labels
package: core @ionic/core package type: bug a confirmed bug report

Comments

@AshishSanu
Copy link

Ionic version:

[x] 4.x

I'm submitting a ...

[ ] bug report
[ ] feature request

Current behavior:

My Modal is appearing with a solid background/Overlay

Expected behavior:

I want my modal to appear with a transparent background/overlay
Steps to reproduce:

Related code:

insert short code snippets here
modal.scss  :
 .main_view{
      background: transparent;
    }
    .overlay {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      z-index: 1;
      opacity: .5;
      background-color: #333;
      
    }

modal.html:
<ion-content padding class="main_view">
  <div class="overlay" (click)="dismiss()"></div>
  <div class="modal_content">
    <div class="circle"></div>
    <div class="modal-content">
        <ion-progress-bar type="indeterminate"></ion-progress-bar>
  <h2>Waiting for Driver confirmation</h2>
    </div>
  </div>
  
</ion-content>

and .ts to invoke modal in my app:

  async confirm(){
    
    const modal = await this.modalCtrl.create({
      component: ModalPage,
      // componentProps: {value : "test"},
    });
    await modal.present();
    modal.onDidDismiss().then(res => {
      console.log(JSON.stringify(res))
      this.isModalDismiss = res.data.isDismiss;
      console.log(this.isModalDismiss)
      this.routeDriver();
    });
  }

Other information:

Ionic info:

insert the output from ionic info here
@ionitron-bot ionitron-bot bot added the triage label Jun 21, 2019
@AshishSanu
Copy link
Author

AshishSanu commented Jun 21, 2019

My Modal Looks like this
Screenshot (57)
I want the overlay to be transparent

@liamdebeasi
Copy link
Member

Hi there,

Thanks for the issue. I can confirm that this is a bug. It looks like ion-modal does accept a --background CSS variable, but if you are using components like ion-header and ion-content you would never see it since those default to white backgrounds.

A temporary workaround would be to set the --background CSS variable for ion-content to transparent in addition to setting the --background CSS variable for ion-modal.

We will look into a solution for this. Thanks!

@liamdebeasi liamdebeasi added package: core @ionic/core package type: bug a confirmed bug report labels Jun 21, 2019
@AshishSanu
Copy link
Author

hi @liamdebeasi workaround is also not working

@ManjeetKSingh
Copy link

I am also facing the same issue...becuse of this our App is delayed to be shhipped for production.
@ionic-team , could you please resolve this issue ASAP.

@gminhaneli
Copy link

Você consegue resolver colocando no arquivo global.scss .modal-transparency { --background: var(--ion-background-color, rgba(0, 0, 0, 0.2)) !important ; }

@codeherk
Copy link

codeherk commented Jun 28, 2019

@AshishSanu Going off what @gminhaneli and @liamdebeasi is proposing, here is a temporary solution.

To produce solution:

  • generate a page for the modal ionic g page <PAGE NAME>
  • import the page module into app.module.ts and include it in the list of imports
  • Define a css class that will be used on ion-modal. This can be placed in variables.scss or global.scss(show below under CSS Class). --background is a css property and you will need to change it.
  • import the page into the .ts where the modal will be present
  • Include the class name you defined in cssClass property (show below under Function). cssClass is a property of ion-modal
  • include a button in the .html file that will present the modal. Have that button call the function that presents the modal.

CSS Class

modal-transparency { 
  --background: transparent; 
  --height: 80%;

 // ion-toolbar {
 //   --background: transparent;
 //   color: white;
 // }
 // ion-content {
 //   --background: transparent;
 // }
}

Function

async confirm(){
  const modal = await this.modalCtrl.create({
    component: ModalPage,
    cssClass: 'modal-transparency'
    // componentProps: {value : "test"},
  });
  await modal.present();
  modal.onDidDismiss().then(res => {
    console.log(JSON.stringify(res))
    this.isModalDismiss = res.data.isDismiss;
    console.log(this.isModalDismiss)
    this.routeDriver();
  });
}

Hope this helps.

@AshishSanu
Copy link
Author

AshishSanu commented Jun 28, 2019

@codeherk @gminhaneli thanks for the response, I tried this but it isn't working

@codeherk
Copy link

codeherk commented Jun 28, 2019

I followed the steps I provided and copied your modal.html..

Screen Shot 2019-06-28 at 5 49 37 AM

Only thing I did not copy was your modal.scss. You did not include the styling for circle and modal-content, so I ignored it altogether.

Here is a screenshot with the stylings from modal.scss applied.
Screen Shot 2019-06-28 at 6 04 57 AM

The div that has the overlay class has a fixed position and it is applied directly over the content, covering the whole screen.

@ae-asseke
Copy link

ae-asseke commented Aug 10, 2019

to have a good transparent (ionic 4), I made this

    • modal.scss { ion-content {
      --ion-background-color : transparent !important;
      }'
    • global.scss {
      modal-transparency {
      --background: transparent!important
      }
    • and I call modal like this
      async confirm(){
      const modal = await this.modalCtrl.create({
      ...
      cssClass: 'modal-transparency'
      ...
      });

I hope it can help u.

@testanddeploy
Copy link

@ae-asseke This not work for me on chrome with ionic serve.

@niravtrivedi21
Copy link

Hi @ionic-team, I am facing the same issue in Ionic 5, can you please guide me to resolve this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: core @ionic/core package type: bug a confirmed bug report
Projects
None yet
Development

No branches or pull requests

9 participants