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

Fix #5019: Nested dialog escape listeners prioritization #5126

Closed
wants to merge 1 commit into from

Conversation

salihozdemir
Copy link
Contributor

Fixed an issue when a dialog is nested, the escape listener for the child dialog should be prioritized over the escape listener for the parent dialog.

fix #5019

@vercel
Copy link

vercel bot commented Oct 20, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
primereact ⬜️ Ignored (Inspect) Visit Preview Oct 20, 2023 1:18pm

@github-actions
Copy link

Thanks a lot for your contribution! But, PR does not seem to be linked to any issues. Please manually link to an issue or mention it in the description using #<issue_id>.

@melloware melloware added the Type: Bug Issue contains a defect related to a specific component. label Oct 20, 2023
@melloware
Copy link
Member

@avasuro can you review this? I am not sure this is correct either?

@avasuro
Copy link
Contributor

avasuro commented Oct 20, 2023

I didn't test the "live" example, but based on the code, the current solution may not work as expected for two reasons:

  • It still relies on the order in which dialogs are rendered. According to the code, it may not work for a situation like this:
    <Dialog visible={true} closable closeOnEscape>visible</Dialog>
    <Dialog visible={false} closable closeOnEscape>hidden</Dialog>
    
    In this case, the hidden dialog will always handle the escape key, so the visible dialog will never be closed (because of stopImmediatePropagation).
  • Similarly, if a dialog is rendered alongside other elements that also listen for the "esc" key, there's no guarantee that another component won't handle the escape key first, and the modal may never be closed again (for the same reason - stopImmediatePropagation)

@salihozdemir
Copy link
Contributor Author

I didn't test the "live" example, but based on the code, the current solution may not work as expected for two reasons:

  • It still relies on the order in which dialogs are rendered. According to the code, it may not work for a situation like this:

    <Dialog visible={true} closable closeOnEscape>visible</Dialog>
    <Dialog visible={false} closable closeOnEscape>hidden</Dialog>
    

    In this case, the hidden dialog will always handle the escape key, so the visible dialog will never be closed (because of stopImmediatePropagation).

  • Similarly, if a dialog is rendered alongside other elements that also listen for the "esc" key, there's no guarantee that another component won't handle the escape key first, and the modal may never be closed again (for the same reason - stopImmediatePropagation)

Hey @avasuro,

Thanks for the review! You're right, the current solution only works limited scenarios. I just saw your PR(#5021) and it looks like you've got a better solution. I'll watch your PR and see if I can help out.

I'm closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dialog: "esc" close dialogs in wrong order
3 participants