ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

bug: IonPopover `keyboardClose={false}` does not prevent keyboard dismissal since ionic 8.7.4

Open Pablosornp opened this issue 5 months ago • 4 comments

Prerequisites

Ionic Framework Version

v8.x

Current Behavior

When an IonPopover with keyboardClose={false} is presented while a text input is focused, the mobile keyboard closes immediately and focus is lost from the initial input.

Expected Behavior

When an IonPopover with keyboardClose={false} is presented while a text input is focused, the mobile keyboard should be kept open and the focus should be held by the initial input.

Steps to Reproduce

  1. Go to: https://stackblitz.com/edit/vitejs-vite-w4vmmzwi. There is a minimal repo project there.
  2. Type @ in the textarea. A popover with user suggestions should appear. On mobile, the keyboard and focus should stay open in the text area so you can type to filter — but it closes immediately due to the bug.
  3. Test using Ionic 8.7.3. In that version it works as expected. You can edit the package.json for that.
Image

Code Reproduction URL

https://stackblitz.com/edit/vitejs-vite-w4vmmzwi

Ionic Info

[WARN] You are not in an Ionic project directory. Project context may be missing.

Ionic:

Ionic CLI : 6.19.0

Utility:

cordova-res : not installed globally native-run : not installed globally

System:

NodeJS : v22.21.1 npm : 11.7.0 OS : Linux 6.19

Additional Information

Please mind that i am only using the Ionic Components in an existing React Project. I am not using Capacitor or any of the other native features.

Pablosornp avatar Jun 08 '26 14:06 Pablosornp

Bean Labs took a source pass. core/src/components/popover/popover.tsx still exposes @Prop() keyboardClose = true, so the regression is about whether the dismiss/open path respects an explicit false, not whether the prop exists.

A minimal fix test would mount an input plus ion-popover keyboard-close="false", open the popover, and assert the keyboard interaction path does not call the keyboard-close utility on dismiss/open transitions. That keeps the test around the component contract instead of the app-level repro.

No PR opened from this pass.

beanscg avatar Jun 09 '26 17:06 beanscg

Hi! Any estimation on where this issue might be at least triaged? This bug must be affecting other users.

Pablosornp avatar Aug 25 '26 09:08 Pablosornp

Thanks for the report, and sorry for the delay.

Verified on 9.0.8. When a popover is presented, Ionic now blurs whatever element had focus before the overlay opens, and it does this before checking keyboardClose. So with keyboardClose={false} the textarea still loses focus, and on mobile the keyboard closes with it.

Workaround, verified on 9.0.8: put focus back on the textarea from onWillPresent. That event fires in the same task as the blur, so focus returns before anything renders:

import { useRef } from 'react';
import { IonContent, IonPopover, IonTextarea } from '@ionic/react';

export function MentionField({ isOpen }: { isOpen: boolean }) {
  const textareaRef = useRef<HTMLIonTextareaElement>(null);

  return (
    <>
      <IonTextarea ref={textareaRef} />
      <IonPopover
        isOpen={isOpen}
        keyboardClose={false}
        onWillPresent={() => textareaRef.current?.querySelector('textarea')?.focus()}
      >
        <IonContent className="ion-padding">Suggestions</IonContent>
      </IonPopover>
    </>
  );
}

Focus the inner textarea directly rather than calling setFocus(). setFocus() resolves a moment later, after the popover's focus trap is active, and the trap pulls focus into the popover. If you use a plain <textarea>, call .focus() on its ref.

Tracked as a bug in core.

thetaPC avatar Oct 20 '26 23:10 thetaPC

I'm opening a PR that skips the blur on present when keyboardClose is false.

adityajai119 avatar Nov 09 '26 14:11 adityajai119