Ionic-datetime calendar widget truncated (beta6)

The calendar widget is cut in half for me, and I’ve pretty much just pasted the demo code from the docs. Any thoughts what I could be doing wrong?
Here is a gif video and below that my code. Thank you.

calendar_truncated

    <ion-item button="true" id="open-date-input">
      <ion-label>Appointment Date</ion-label>
      <ion-text slot="end">{{ dateValue }}</ion-text>
      <ion-popover trigger="open-date-input" show-backdrop="false">
        <ng-template>
          <ion-datetime
            #popoverDatetime
            presentation="date-time"
            (ionChange)="dateValue = formatDate(popoverDatetime.value)"
          >
          </ion-datetime>
        </ng-template>
      </ion-popover>

    </ion-item>

From this link I found out that the width is being hardcoded, which led to a fix.

please try to place the ion popover outside of the ion item at the end of you html page

Do you mean move the ion-popover outside so the structure is like below? I tried and the whole datetime input just goes away. Thanks.

<ion-popover..>
  <ion-item>
  ..
  </ion-item>
</ion-popover>

No i mean a structure like:

<ion-content>
...
</ion-content>

<ion-popover trigger="open-date-input" show-backdrop="false">
  <ng-template>
    <ion-datetime
      #popoverDatetime
      presentation="date-time"
      (ionChange)="dateValue = formatDate(popoverDatetime.value)"
    >
    </ion-datetime>
  </ng-template>
</ion-popover>

I tried taking the ion-item out but it doesn’t open the date popover.
I use the several times like this as part of a form, and the one surrounding the ion-popover makes it open. Sorry that I’m not understanding.

<ion-content>
  <form [formGroup]="apptForm" (ngSubmit)="submitForm()" novalidate>
    <ion-item>
      <ion-label>Technician</ion-label>
      <ion-select formControlName="workerId" required interface="popover">
        <ion-select-option *ngFor="let user of users$ | async" value="{{user.id}}">{{user.name}}</ion-select-option>
      </ion-select>
    </ion-item>
    <span class="error ion-padding" *ngIf="isSubmitted && errorControl.workerId.errors?.required">
      Service technician is required.
    </span>
    <ion-item button="true" id="open-date-input">
      <ion-label>Appointment Date</ion-label>
      <ion-text slot="end">{{ dateValue }}</ion-text>
      <ion-popover trigger="open-date-input" show-backdrop="false">
        <ng-template>
          <ion-datetime
            #popoverDatetime
            presentation="date-time"
            (ionChange)="dateValue = formatDate(popoverDatetime.value)"
            formControlName="apptDate"
            required>
          </ion-datetime>
        </ng-template>
      </ion-popover>
    </ion-item>
    <span class="error ion-padding" *ngIf="isSubmitted && errorControl.apptDate.errors?.required">
      Appointment date is required.
    </span>  
    <ion-item lines="full">
      <ion-label position="floating">Appointment Prep Notes</ion-label>
      <ion-input formControlName="prepNotes" type="text"></ion-input>
    </ion-item>    
    <ion-row>
      <ion-col>
        <ion-button color="danger" (click)="cancel()">Cancel</ion-button>
      </ion-col>
      <ion-col>
        <ion-button type="submit" color="danger" expand="block">Submit</ion-button>
      </ion-col>
    </ion-row>
  </form>
</ion-content>

You are nor reading what i write… Look into it again, you should try to move the POPOVER out of the content

You are correct, I did not read you properly. Sorry about that, I will try to move those things outside the ion-content itself. The problem is I don’t fully understand their purpose and how they interact with each other, but will research it more. And thanks again for your patience! Your help is educational.

Hans, I’m gonna give up for now as the CSS fix seemed to be enough. Moving the popover out of the ion-content, or removing the ion-content entirely, caused other problems that are beyond my ability to fix easily.

I do appreciate your attempt to help! Thanks again.

Hello,

I played a little with the inline popover and they are kind of a nightmare. Mostly because when you reload the page you can’t do anything else with them. What I did was place the ion-datetime in a seperate component and open the popover programmatically. If you’d like I can post it here, but it’s pretty basic ion-popover implementation using PopoverController

1 Like

I am interested in seeing your code anyway, please post. Thank you!

Fisrt I generated a component using the ionic cli: ionic g c datetime
Then generated a module for that component: ionic g module datetime

The module is just so I can reuse the component wherever I want by exporting the component in the module and importing it in the module of the page I wanna use it in.

datetime.component.html:

<ion-datetime>
  <div slot="title">My Custom Title</div>
</ion-datetime>

datetime.module.ts:

@NgModule({
  imports: [CommonModule],
  declarations: [DatetimeComponent],
  exports: [DatetimeComponent]
})
export class DatetimeModule { }

datetime.component.scss:

ion-datetime {
  margin: auto;
}

This css is just to centralize the ion-datetime in the datetime component when using it as a custom component.

some-page.page.html:

<ion-content>

  <ion-button color="success" (click)="openDatetimePopover($event)" expand="block" fill="solid">
    <ion-label>PopoverController</ion-label>
  </ion-button>

  <ion-button color="success" id="trigger-button" expand="block" fill="solid">
    <ion-label>Inline Popover</ion-label>
  </ion-button>

  <ion-popover trigger="trigger-button">
    <ng-template>
      <app-datetime></app-datetime>
    </ng-template>
  </ion-popover>

  <h2>As a custom component</h2>
  <app-datetime></app-datetime>
</ion-content>

Above is also the implementation of an inline popover containing an ion-datetime. Sometimes it works, sometimes it just doesn’t open and don’t throw any errors. I don’t know if that only happens with me or if is bug with ionic itself, if it is I’m sure they are gonna fix it when they release the stable version of Ionic 6

some-page.page.ts:

  constructor(private popoverController: PopoverController) { }

  async openDatetimePopover(event) {
    const popover = await this.popoverController.create({
      component: DatetimeComponent,
      event,
      cssClass: 'datetime-popover'
    });
    popover.present();
  }

some-page.module.ts:

@NgModule({
imports: [
   ...
   DatetimeModule,
]

global.scss:

.datetime-popover {
  --width: 80vw;
  --max-width: fit-content;
}

You can test to see if everything works for you, if it doesn’t just say what happens and we can see what else can we try.

Also I apologize for my poor english, I’m not a native speaker :smile:

Your English is just fine…! Thanks for the code I will study and try sometime. I have to learn a bit about making my own components, so far I have avoided doing that…!

I feel you. Until last year I was afraid of using it too. But trust me: it’s simple and make your life so much easier. You can try the approach I used here(create a component and a module for it, export the component in it’s module and import the module anywhere you want to use them) or you can check out this approach, where the guy uses one module for multiple components.

What kinds of issues are you running into with the inline popover?

The issue here looks to be that the popover is not expanding to match the datetime size. Can you file an issue here? Issues · ionic-team/ionic-framework · GitHub

Sometimes it doesn’t open, I click the trigger and nothing happens, and I mean nothing, no popover, no errors, nothing.
It happened last month when I first tried using it. But I needed to deploy to production so I deleted everything and just used PopoverController. I had forgotten this so for the code I posted here I had to implement it again and had no problems. Maybe is already fixed?

We’ve fixed some issues with popovers/modals in the past few releases, so you could try it again and let me know if the issue persists.

I’ll do that. Thanks for now.