To close `ion-datetime` on clicking hardware back button

I am trying to close the ion-datetime after hitting the back button but i couldn’t able to do (ionic v-4).But after hitting screen, cancel/done buttons the dialog(ion-datetime) is closing.

<ion-datetime display-format="MMM DD, YYYY" ></ion-datetime>

I tried this solutions:

Still the same issue exists.

As temporary “ugly” solution, you could call this function to close the datetime input:

  const dismiss = () => {
    const picker = window.document.querySelector('ion-picker')!
    if (picker) picker.dismiss()
  }

Note that this only works if you have a single ion-picker opened. This also works for @ionic/react’s IonDateTime component.