8

I want to change the popover width of only 1 page. I tried this:

I do not want to use this $popover-ios-width in variable.scss files since it changes the width on all pages.

6 Answers 6

14

You can create a custom class for only this popover and pass it in the cssClass on it's options

let's say you have this:

.custom-popover { width: 60%; } 

In your popover creation you'll just insert it as the cssClass on the options

const customPopOver = this.popover.create({ yourPopoverPage, yourData, { cssClass: 'custom-popover'}}); customPopOver.present(); 

Hope this helps :D

Sign up to request clarification or add additional context in comments.

4 Comments

I put the .customer-popover class in my .scss file and called from my .ts file the popover with the same name, it is still the same size
the .custom-popover class should be declared globally as ion-popover is not on the same context as the page component.
as @afifahmi said it needs to be globally, put your .customer-popover in the app.scss file inside app folder.
@GabrielBarreto where would I put this if I am using an ion-select with the popover interface?
14

@gabriel-barreto's answer is totally fine. However, I guess it needs an additional consideration in other versions.

In Ionic 3.6 the custom class is added to the <ion-popover> element. In order to override the default width rule set in .popover-content class, your selector should be:

.custom-popover .popover-content { width: 60%; } 

Comments

3

Add this below code in variables.scss. works for me in Ionic 4.

ion-popover { .popover-wrapper { .popover-content { width: fit-content; max-width: 300px; } } } 

2 Comments

This still works for Ionic 5, however I don't think this is the recommended way. In the docs (ionicframework.com/docs/api/popover#css-custom-properties) they describe custom css properties: --max-width and --width. Issue is: I just don't have a clue how to use them and it's not described anywhere. Any idea?
The solution also works for Ionic 5. I will do the recommended way later. Until then you can use this solution.
1

I do not know if it will still suit you, I found the same problem, but modifying the global variable scss configuration did not help me because I used multiple PopoverControllers in the project the only way I managed to do it is the following:

  1. Place the ion-content as a parent element and add the id attribute
  2. Get Parent Items to the Main Container:

ionViewDidLoad() { let element = document.getElementById('id') let parent=element.parentElement let parent2 = parent.parentElement //popover-content parent2.parentElement.style['width'] = "92px" }

3 Comments

Ok Thanks Ill try that
Can you post your html? I am confused which ion-content
<ion-content id="align-format"> <ion-list> <ion-list-header> Align </ion-list-header> <ion-item (tap)="setAlign('left')"><i class="fa fa-align-left fa-2x" aria-hidden="true"></i></ion-item> <ion-item (tap)="setAlign('center')"><i class="fa fa-align-center fa-2x" aria-hidden="true"></i></ion-item> <ion-item (tap)="setAlign('right')"><i class="fa fa-align-right fa-2x" aria-hidden="true"></i></ion-item> <ion-item (tap)="setAlign('justify')"><i class="fa fa-align-justify fa-2x" aria-hidden="true"></i></ion-item> </ion-list> </ion-content>
1

Try this...

myPopOver = this.popovercontroller.create({ component: MyCustomComponent, event:ev, cssClass: 'my-custom-popover' }) myPopOver.present(); 

add my-custom-popover class in global.css file.

Comments

1
const customPopOver = this.popover.create({ yourPopoverPage, yourData, { cssClass: 'custom-popover'}}); 

You need to create popover and add cssClass prop as on code above, then you can use 'custom-popover' class in variables.scss file like below.

.custom-popover { .popover-wrapper { .popover-content { width: 465px; } } 

}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.