Skip to content
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

Dialog: Focus from input lost in very short time after dialog opened #11860

Closed
martin654 opened this issue May 3, 2024 · 6 comments · Fixed by #11862
Closed

Dialog: Focus from input lost in very short time after dialog opened #11860

martin654 opened this issue May 3, 2024 · 6 comments · Fixed by #11862
Assignees
Labels
🐞 defect Bug...Something isn't working
Milestone

Comments

@martin654
Copy link

martin654 commented May 3, 2024

Describe the bug

Hi,
we have many dialogs in our app and our users were uset that focus was set inside the dialog when dialog opened - for example into first input component. That worked great in version 13.0.5 but since 13.0.6 this doesn't work anymore. I tried it with 13.0.9 and it is still broken.

In the browser you can see that focus is applied for short amount of time and then lost.

Please see attached reproducer.

Thanks

Reproducer

Please see attached reproducer:
primefaces-test_dialog_focus.zip

Expected behavior

I expect PF to work the same as in PF version 13.0.5 and earlier...

PrimeFaces edition

Elite

PrimeFaces version

13.0.6

Theme

No response

JSF implementation

Mojarra

JSF version

4.0.7

Java version

17

Browser(s)

Chrome

@martin654 martin654 added ‼️ needs-triage Issue needs triaging 🐞 defect Bug...Something isn't working labels May 3, 2024
@martin654
Copy link
Author

martin654 commented May 3, 2024

Description in this ticket:
#11818

"Since PF 13.0.6, setting the focus with the 'focus' attribute in the 'dialog' no longer works. The element briefly gains focus and then immediately loses it again. This still worked in PF 13.0.5."

looked like it could be related

@martin654
Copy link
Author

Looks like it is caused by this change:
bc7bc91

@melloware melloware changed the title dialog: Focus from input lost in very short time after dialog opened Dialog: Focus from input lost in very short time after dialog opened May 3, 2024
@melloware melloware removed the ‼️ needs-triage Issue needs triaging label May 3, 2024
@melloware melloware self-assigned this May 3, 2024
@melloware melloware added this to the 14.0.1 milestone May 3, 2024
@melloware
Copy link
Member

Thanks for the reproducer let me debug this issue.

@melloware
Copy link
Member

@martin654 great reproducer this was tricky to debug. What is happening is both dialogs called show before the first hide is executed and the delay is causing the focus change. here is the debug.

applyFocus ajaxDialog
Start AJAX
applyFocus searchDialog
Complete AJAX
returnFocus 
<button id="frmTest:openDialogButton" 

Working on a fix

@melloware
Copy link
Member

pf-11860.zip

I included a monkeyPatch in your test.js can you give it a try?

if (PrimeFaces.widget.Dialog) {
  PrimeFaces.widget.Dialog.prototype.returnFocus = function () {
    var el = this.focusedElementBeforeDialogOpened;
    if (el) {
      // #11860 do not return focus if other dialogs are still open
      var otherDialogs = $(".ui-dialog:visible").length > 0;
      if (otherDialogs) {
        return;
      }
      setTimeout(function () {
        el.focus({ preventScroll: true });
      }, 100);
    }
  };
}

melloware added a commit to melloware/primefaces that referenced this issue May 3, 2024
melloware added a commit to melloware/primefaces that referenced this issue May 3, 2024
@melloware melloware modified the milestones: 14.0.1, 13.0.10 May 4, 2024
melloware added a commit to melloware/primefaces that referenced this issue May 4, 2024
Fix primefaces#11860: 13.0.10 Dialog returnFocus when other dialogs open
melloware added a commit to melloware/primefaces that referenced this issue May 4, 2024
Fix primefaces#11860: 13.0.10 Dialog returnFocus when other dialogs open
melloware added a commit to melloware/primefaces that referenced this issue May 4, 2024
Fix primefaces#11860: 13.0.10 Dialog returnFocus when other dialogs open
melloware added a commit that referenced this issue May 4, 2024
Fix #11860: 13.0.10 Dialog returnFocus when other dialogs open
@martin654
Copy link
Author

@melloware Thank you for the fix, works great in 13.0.10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 defect Bug...Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants