Skip to content

bug: Focus flashes on input field when opening a modal from a popover #24820

@raymer

Description

@raymer

Prerequisites

Ionic Framework Version

  • v4.x
  • v5.x
  • v6.x

Current Behavior

When opening a modal from a popover click event, if that modal has form fields, the first one is given immediate focus, then immediately blurred, causing a flashing effect.

Expected Behavior

The input field in a modal opened by a popover does not receive focus then immediately blur.

Steps to Reproduce

Create an inline popover that has a child with a click event that opens a modal that contains an input field.

Page with popover

<template>
  <ion-page>
    <ion-content :fullscreen="true" color="light">
      <ion-button @click="setOpen(true, $event)" shape="round" fill="clear" color="dark" size="small">
        <ion-icon :icon="ellipsisVertical"></ion-icon>
      </ion-button>
      <ion-popover :is-open="isOpen" :event="locationEvent" :dismissOnSelect="true" @didDismiss="setOpen(false)">
        <ion-item class="context-item" lines="full" @click="openModal">Test</ion-item>
      </ion-popover>
    </ion-content>
  </ion-page>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { IonButton, IonPopover, IonIcon, IonPage, IonContent, modalController, IonItem } from '@ionic/vue';
import { ellipsisVertical } from 'ionicons/icons';
import ModalVue from './Modal.vue';

const isOpen = ref(false);
const locationEvent = ref<Event>();

function setOpen(state: boolean, event?: Event) {
  locationEvent.value = event;
  isOpen.value = state;
}

const openModal = async () => {
  const modal = await modalController
    .create({
      component: ModalVue
    })
  modal.present();
  await modal.onDidDismiss();
}
</script>

Modal.vue

<template>
  <ion-item>
    <ion-label position="floating">Label</ion-label>
    <ion-input></ion-input>
  </ion-item>
</template>

<script lang="ts" setup>
import { IonItem, IonLabel, IonInput } from '@ionic/vue';
</script>

Code Reproduction URL

https://github.com/raymer/ionic-bug

Ionic Info

Ionic:

Ionic CLI : 5.4.16 (C:\Users\rayme\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : @ionic/vue 6.0.1

Capacitor:

Capacitor CLI : 3.2.4
@capacitor/core : 3.4.1

Utility:

cordova-res : not installed
native-run : 1.5.0

System:

NodeJS : v16.13.1 (C:\Program Files\nodejs\node.exe)
npm : 8.3.0
OS : Windows 10

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions