How to change the width of the ionic popover - ionic-framework

I had created the ionic popup. Created a popover page and added action on button click to display popover from home page. but iam unable to change the width of the popover. below is the code;
home.page.html:
<ion-content>
<ion-button expand="full" (click)="openPopover($Event)">Open popover</ion-button>
</ion-content>
home.page.ts:
async openPopover(ev: Event) {
const popover = await this.popoverController.create({
component:PopoverPage,
componentProps: {
custom_id: this.value
},
});
popover.present();
}
popover.page.html:
<ion-content>
<ion-list>
<ion-item>
this is popover
</ion-item>
<ion-item button color="danger" (click) = "closePopover()">
<ion-icon name="close" slot="start"></ion-icon>
Close Popover
</ion-item>
</ion-list>
</ion-content>
popover.page.ts:
closePopover() {
this.popoverController.dismiss();
}
please assist me how can i change the width of the popover as i tried adding custom css to the ion-content of the popover page but its not working.

The other method did not work for me, these changes need to be made:
First the .contact-popover .popover-content{ width: 320px; } content needs to be in global.scss
" This means that any custom styles need to go in a global stylesheet file. In an Ionic Angular starter this can be the src/global.scss file or you can register a new global style file by adding to the styles build option in angular.json." (says in documentation)
Second the CSS cannot be width, it needs to be --width. The custom css properties for this are at the bottom of this: https://ionicframework.com/docs/api/popover

two ways:
override the SCSS variables;
$popover-md-width: 320px; $popover-ios-width: 320px; $popover-wp-width: 320px;
or 2. give your popover a class:
let popover = this.popover.create(ContactPopover, {}, {cssClass: 'contact-popover'})
and then style the .popover-content:
.contact-popover .popover-content{ width: 320px; }
Ionic automatically calculates the correct position for your custom width popover.

Ionic ^4 Popover width can be modified on a global level adding the following to the styles.scss file:
ion-popover {
--width: 320px;
}

For ionic 6.x the solution is
ion-popover {
&::part(content) {
min-width: 230px;
}
}

Related

How to achieve ionic modal auto-dismiss on clicking outside or hardware back button

Hi i am working on an ionic project, where in the home page there is a button on clicking which a modal will appear with a slider inside it. Now when i am opening the modal for the very first time its showing the modal with the slider correctly then i clicked outside of the modal and it's closed. Now if the click the button again, now the modal is shown but the slider is not working any more, it looses the slider property and pager. What i may have missed --
on button click this is the code --
this.modalController.create({
component: VipModalPage,
cssClass: 'my-custom-modal-css',
componentProps: {
uid: event.payload.uid
}
}).then(modal => modal.present());
I tried using backdropDismiss: true but no luck.
Code of the modal slider --
<ion-content>
<ion-slides [options]="sliderOpts" pager="true" loop="true">
<ion-slide>
<ion-img src="../../../assets/images/01.png"></ion-img>
<h2>Text Heading</h2>
<p>Text Paragraph</p>
</ion-slide>
<ion-slide>
<ion-img src="../../../assets/images/02.png"></ion-img>
<h2>Text Heading</h2>
<p>Text Paragraph</p>
</ion-slide>
<ion-slide>
<ion-img src="../../../assets/images/03.png"></ion-img>
<h2>Text Heading</h2>
<p>Text Paragraph</p>
</ion-slide>
</ion-slides>
</ion-content>
modalpage.ts --
import { Component, OnInit } from '#angular/core';
#Component({
selector: 'app-vip-modal',
templateUrl: './vip-modal.page.html',
styleUrls: ['./vip-modal.page.scss']
})
export class VipModalPage implements OnInit {
sliderOpts = {
initialSlide: 0,
slidesPerView: 1,
autoplay: {
disableOnInteraction: false
}
};
constructor() {
}
ngOnInit() {
}
}
This is the css part --
.my-custom-modal-css .modal-wrapper {
height: 60%;
width: 80%;
top: 20%;
bottom: 20%;
left: 10%;
right: 10%;
position: absolute;
display: block;
}
Finally solved the issue, steps --
1. In modal.page.ts --
Created a function to load data in an array for the slider.
And called the function here
ionViewWillEnter() {
this.loadData();
}
In modal.page.html --
Using ngFor display array values in slider.
Now everytime the modal opens then it loads the fresh data and slider is working properly everytime.

Ionic 3 how to change the background colour of selected radio button in ion-item container

I need to change the background color of the selected radio input.
I have the following ion-radio list:
<ion-list radio-group [(ngModel)]="selectedRadio">
<ion-item *ngFor="let ing of pizzaIng; let i = index">
<ion-label>{{ing.name}}</ion-label>
<ion-radio [value]="ing.name"></ion-radio>
</ion-item>
</ion-list>
The only way it's working, is by overriding item-md class of ion-item into:
ion-item.item-md{
background-color: red;
}
But its changing all the radio options displayed. How can I only change the color of the selected one?
Here is a prepared stackblitz for it.
got this to work on my ionic 3 project and works in your demo. also just a heads up on using classes with 'md' at the end will only effect android.
.css
page-home {
.item-radio-checked{
background-color: #a0a;
}
}

How to set IONIC4 set tabs background transparent?

I use ionic4 now. And my client and his designer give a picture like below.
It need to make tabs has transparent but I don't know how to set. I have try to add in variables.scss but the transparent is no working. If only change color is work.
.ion-color-tabstrans {
--ion-color-base: rgba(100,100,100,0.1);;
}
From the tab-bar docs seems like you can change the background by using the --background CSS property like this:
HTML
<ion-tabs>
<!-- Tab bar -->
<ion-tab-bar class="my-custom-tab-bar" slot="bottom">
<ion-tab-button tab="account">
<ion-icon name="person"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="contact">
<ion-icon name="call"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="settings">
<ion-icon name="settings"></ion-icon>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs>
SCSS
ion-tab-bar.my-custom-tab-bar {
--background: rgba(100,100,100,0.1);
}
EDIT
You'd probably need to change the background of the ion-tab-button as well
ion-tab-bar.my-custom-tab-bar ion-tab-button {
--background: transparent;
}
EDIT II
The answer above is correct, but is missing something that makes everything not to work as expected. The problem is that the ion-tabs element is placed outside of the element that represents the content. What you need based on your question is to place the tabs above the content instead.
One way to do that is by setting the positioning of the ion-tabs to be absolute, like this:
HTML
<ion-tabs>
<!-- I've added a my-custom-tab-bar class to the ion-tab-bar element -->
<ion-tab-bar class="my-custom-tab-bar">
<!-- ... -->
</ion-tab-bar>
</ion-tabs>
SCSS
ion-tab-bar.my-custom-tab-bar {
position: absolute;
bottom: 0;
width: 100%;
--background: rgba(255,255,255,0.8);
ion-tab-button {
--background: transparent;
}
}
That produces this result:
Notes
Please notice that since the tabs are above the content, you will need to add some margin-bottom to the content of each page that is used as a tab.
Also please double check if setting the positioning of the tabs to be absolute doesn't break the layout specially in devices with a safe-area at the bottom like the iPhone X.

Footer visible during navigate from Page2 to Page1

ion-footer button doesn't disappear properly when navigating from page1 to page2 and then navigate back from page2 to page1.
Here's the code in page2:
<ion-footer padding>
<button ion-button block round color="primary">Add to Order</button>
</ion-footer>
I have found an exact same issue on github which recommend adding tag ion-toolbar
but it didn't work for me:
ion-footer on back should disappear on willLeave not didLeave
Footer Visible During Navigation Transition
Nav animations for ion-footer-bar and ion-header-bar
Any comments/answers are appreciated!
Create a new class, say, .app-footer, with the same CSS properties as ion-footer and place the HTML within ion-content, like so:
HTML
<ion-content>
<page code>
<div class="app-footer">...</div>
</ion-content>
SCSS
.app-footer {
left: 0;
bottom: 0;
position: absolute;
z-index: 10;
display: block;
width: 100%;
}
Finally, I make it work, wrap button in div tag with padding solved my issue:
<ion-footer>
<div padding>
<button
ion-button block round color="primary"
[disabled]="items.length === 0" (click)="onContinueClick()">
Continue
</button>
</div>
</ion-footer>
On ionic version 6 i had the same problem, and for those who are facing the same, the solution that worked for me was enclosing the content of ion-footer into an ion-content
Code example:
<ion-footer>
<ion-content>
Your footer content
</ion-content>
</ion-footer>
In my case i had also to set a height to ion-footer for example:
ion-footer{
height: 6rem;
}

How to change header/nav bar in Ionic 2

I have a custom < ion-header > background design with a CSS clip path that creates a slanted look. I want to be able to change the navbar to a standard ionic nav bar design as the use scrolls down the page.
What I want to achieve is as the user scrolls down I want it to change to a standard nav bar and as user scrolls to top of the page to go back to my custom background
<ion-header no-border class="discoverHeaderx" >
<ion-navbar class="feedNavbarDiscover" no-fixed no-border>
<button ion-button menuToggle>
<ion-icon name="menu" color="purple"></ion-icon>
</button>
<ion-title ></ion-title>
</ion-navbar>
</ion-header>
SCSS
.discoverHeaderx{
background-size: cover;
border:none;
background: url('../assets/img/discover_bg.svg');
background-color:#ffe680;
-webkit-clip-path: polygon(50% 0%, 100% 0, 100% 75%, 50% 100%, 0% 75%, 0 0);
clip-path: polygon(50% 0%, 100% 0, 100% 75%, 50% 100%, 0% 75%, 0 0);
}
You can do this with Content from ionic-angular. So in your .TS file you'll need this:
import { ViewChild } from '#angular/core';
import { Content } from 'ionic-angular';
export class YourPage {
#ViewChild(Content) content: Content; // getting a reference to the content
public offsetFromTop: number = 0;
// EVERYTIME YOU SCROLL YOUR PAGE IT'LL GET THE NUMBER OF PX IT HAS SCROLLED AWAY FROM THE TOP
checkIfTop() {
this.offsetFromTop = this.content.scrollTop;
}
}
And in your HTML you'll conditionally use the class that'll customize your header
<ion-header no-border [ngClass]="{'discoverHeaderx': offsetFromTop == 0}">
<!-- THIS'LL ADD YOUR CLASS IF THE USER IS ON TOP OF THE PAGE, IF YOU
WANT TO SHOW THE CUSTOMIZED HEADER EARLIER YOU CAN USE offsetFromTop < x AND X BEEING A NUMBER YOU WANT. -->
<ion-navbar class="feedNavbarDiscover" no-fixed no-border>
<button ion-button menuToggle>
<ion-icon name="menu" color="purple"></ion-icon>
</button>
<ion-title ></ion-title>
</ion-navbar>
</ion-header>
For this to work you'll need to add an scroll event to your ion-content to execute your function everytime you scroll
<ion-scroll (ionScroll)="checkIfTop()">
...
</ion-scroll>
Your question about the non fixed header is the same as the first one about "switching" the headers. But fyi the header is always fixed on tp of page, it'll not be if you use it inside <ion-content>, but in your case since you just want to switch the header style the code will work.
Hope this helps.