Ion-datetime : disable opening keyboard

Good day,

I already search the forums and the webs for similar issues, but haven’t found anything useful yet.

I’m using “@ionic/angular”: “^6.1.9” and show an ion-datetime. On android when the time-selector modal is open and the current set hour or minute is tapped, the number-keyboard opens (and obstructs a part of the modal, but that’s another issue). Same happens on iOS where it’s even worse, because there’s no dedicated button to dismiss the keyboard.

                  <ion-datetime name="startDate"

Please see the screenshot:

Is there a way to prevent the keyboard from opening at all?

Thanks a lot in advance for any hints.

Reading further through the documentationinputmode="none" did not help, since it seems it’s not supported in datetime.

Looking at the source, the numericInput attribute makes the keyboard open. I’ve tried the datetime basic test without that attribute and the keyboard does not open. I’m not that familiar with the ionic source (yet), but maybe I’m able to create a pull request.

Anyone volunteering to help?

What would be the preferred way to disable keyboard input? inputmode="none" or something else?

EDIT: This change makes it work like I need it:

diff --git a/core/src/components/datetime/datetime.tsx b/core/src/components/datetime/datetime.tsx
index ae07f5819..1224ab5db 100644
--- a/core/src/components/datetime/datetime.tsx
+++ b/core/src/components/datetime/datetime.tsx
@@ -222,6 +222,13 @@ export class Datetime implements ComponentInterface {
   @Prop() clearText = 'Clear';

+  /**
+   * The input mode for the time-picker. 'none' will not set the 'numericInput' attribute on the
+   * time picker, unset or 'numeric' will set the  'numericInput' on the time picker resulting
+   * in opening a numeric keyboard on mobile devices if the current value is tapped.
+   */
+  @Prop() inputmode?: 'none' | 'numeric';
    * Values used to create the list of selectable years. By default
    * the year values range between the `min` and `max` datetime inputs. However, to
@@ -1533,7 +1540,7 @@ export class Datetime implements ComponentInterface {
     ampmItems: PickerColumnItem[],
     use24Hour: boolean
   ) {
-    const { color, activePartsClone, workingParts } = this;
+    const { color, activePartsClone, workingParts, inputmode } = this;

     return (
@@ -1541,7 +1548,7 @@ export class Datetime implements ComponentInterface {
-          numericInput
+          { ...inputmode == 'none' ? '' : 'numericInput'}
           onIonChange={(ev: CustomEvent) => {
@@ -1559,7 +1566,7 @@ export class Datetime implements ComponentInterface {
-          numericInput
+          { ...inputmode == 'none' ? '' : 'numericInput'}
           onIonChange={(ev: CustomEvent) => {

I took some time to compare the keyboard input of the ionic time picker with the iOS native one, there are some differences:

Locale is de_at, so we’re dealing with 24h time.

  • input 0 0 0 0 with the keyboard
    ** iOS native widget: time is set to 00:00 (seems correct)
    ** Ionic widget: original time value was 08:13, resulting time is 08:00 :man_shrugging:
  • input 1 1 1 1 with the keyboard
    ** ios native widget: time is set to 11:11
    ** ionic widget: (original time 08:13) time is set 11:11
  • input 2 2 2 2 with the keyboard
    ** ios native widget: time is set to 22:22
    ** ionic widget: (original time 08:13) time is set to 02:22

Looks like there are some issues with handling the keyboard input anyway… Shall I open a bug report?

We have an open bug report for some of the issues you mentioned here: bug: datetime, typing into time picker does not update value prop · Issue #25560 · ionic-team/ionic-framework · GitHub. A fix is in progress here: fix(datetime): typing in time now updates value by liamdebeasi · Pull Request #25561 · ionic-team/ionic-framework · GitHub

The keyboard input for datetime is not a 1-to-1 remake of the iOS keyboard behavior, so I would not expect the behaviors to be exactly the same. The keyboard input in Ionic is more like a select (similar to how <select> works) while the iOS one is a freeform text input.

For example, in iOS 15 you could type “62” into the minutes field:

In Ionic you cannot do that because there is no minute 62. In iOS 16, Apple revised the behavior so you can no longer do that, bringing the behavior closer to Ionic’s.

Thanks for the reply and clearing things up. I’m just getting into mobile development and do not know all the de-facto standards and behaviours yet.

I took the iOS datetime picker as a reference, since I did not have an Android device at hand at the time. The Android picker seems to work a little different with the keyboard input: it highlights the field which currently “gets” the keyboard input.
I guess once the layout issue is fixed, that the picker is not hidden by the keyboard, I’m good.