Skip to content

bug: scroll assist causes duplicate click and focus events to be fired #25200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
4 of 7 tasks
KWIPPED opened this issue Apr 27, 2022 · 7 comments
Open
4 of 7 tasks

bug: scroll assist causes duplicate click and focus events to be fired #25200

KWIPPED opened this issue Apr 27, 2022 · 7 comments
Labels
package: core @ionic/core package type: bug a confirmed bug report

Comments

@KWIPPED
Copy link

KWIPPED commented Apr 27, 2022

Prerequisites

Ionic Framework Version

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

Current Behavior

When ion-input and ion-item gains focus, an ionBlur event is fired incorrectly.

Action Events Fired Status
Click inside ion-input (input gains focus) 1. ionFocus, 2. ionBlur, 3. ionFocus Incorrect
Click inside ion-input (input loses focus) 1. ionBlur Correct

Expected Behavior

Action Events Fired
Click inside ion-input (input gains focus) 1. ionFocus
Click inside ion-input (input loses focus) 1. ionBlur

Steps to Reproduce

  1. Checkout the provided code
  2. run ionic serve
  3. Open inspector
  4. Click in ion-input on the screen

Code Reproduction URL

https://github.com/KWIPPED/ionic-event-bug

Ionic Info

Ionic:

Ionic CLI : 6.19.0 (/usr/local/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/vue 6.1.2

Capacitor:

Capacitor CLI : 3.5.0
@capacitor/android : not installed
@capacitor/core : 3.5.0
@capacitor/ios : not installed

Utility:

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

System:

NodeJS : v14.16.0 (/usr/local/bin/node)
npm : 6.14.11
OS : macOS Monterey

Additional Information

No response

@ionitron-bot ionitron-bot bot added the triage label Apr 27, 2022
@liamdebeasi
Copy link
Contributor

Thanks for the issue. Which browser/version are you testing this on?

@liamdebeasi liamdebeasi added the needs: reply the issue needs a response from the user label Apr 27, 2022
@ionitron-bot ionitron-bot bot removed the triage label Apr 27, 2022
@KWIPPED
Copy link
Author

KWIPPED commented May 2, 2022

On Chrome - Version 100.0.4896.127 (Official Build) (x86_64)

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels May 2, 2022
@liamdebeasi
Copy link
Contributor

Did you push your complete reproduction to the linked repo? I only see a blank starter application.

@liamdebeasi liamdebeasi added the needs: reply the issue needs a response from the user label May 2, 2022
@ionitron-bot ionitron-bot bot removed the triage label May 2, 2022
@KWIPPED
Copy link
Author

KWIPPED commented May 12, 2022

No I didn't. I am so sorry. Now I have pushed it. Simple code in HomePage.vue. ONE IMPORTANT NOTE. Just noticed it. When the inspector is open in Chrome, toggle the device toolbar and select an iPhone. (I used iPhone12). If the behavior does not show at first, reload the page (which will present the iPhone identity to Ionic).

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels May 12, 2022
@liamdebeasi
Copy link
Contributor

liamdebeasi commented May 17, 2022

Thanks, I can reproduce this behavior. This problem is related to our scroll assist utility. The scroll assist utility ensures that inputs are not covered by the keyboard when the keyboard opens. It works by cloning the input and temporarily moving the original input offscreen while the content scrolls the input into the correct place.

This is done by setting pointer-events: none on ion-input and translating the input offscreen:

componentEl.style.pointerEvents = 'none';
inputEl.style.transform = `translate3d(${tx}px,${inputRelativeY}px,0) scale(0)`;

Unfortunately, this causes the browser to blur the input. As a result, we manually call focus to focus the input: https://github.com/ionic-team/ionic-framework/blob/main/core/src/utils/input-shims/hacks/scroll-assist.ts#L66

This results in the duplicate focus and additional blur events you are seeing.

@liamdebeasi liamdebeasi changed the title bug: ionBlur fires when ionFocus fires on at least ion-input and ion-item bug: scroll assist causes duplicate focus events to be fired May 17, 2022
@liamdebeasi liamdebeasi added package: core @ionic/core package type: bug a confirmed bug report labels May 17, 2022
@ionitron-bot ionitron-bot bot removed the triage label May 17, 2022
@liamdebeasi liamdebeasi changed the title bug: scroll assist causes duplicate focus events to be fired bug: scroll assist causes duplicate click and focus events to be fired Jul 14, 2023
@mohamednagy
Copy link

@liamdebeasi i'm in v8 and experiencing same problem, is there a solution for that ?

@liamdebeasi
Copy link
Contributor

Hi there,

I do not work for Ionic anymore, so I won't be much help in getting this resolved. Sorry about that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: core @ionic/core package type: bug a confirmed bug report
Projects
None yet
Development

No branches or pull requests

3 participants