Skip to content

fix(kit): escape key propagation in preview dialog to prevent closing parent dialog #11419

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
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 24, 2025

Problem

When a preview dialog is opened inside a regular dialog, pressing Escape closes both components simultaneously instead of closing only the preview dialog first.

Reproduction:

// Open a dialog that contains a preview
this.dialogs.open(() => {
    // Open preview dialog inside regular dialog
    this.previewDialogs.open('Preview content').subscribe();
    return 'Dialog with preview content';
}).subscribe();

// Press Escape → Both dialogs close at once (incorrect behavior)
// Expected: First escape closes preview, second escape closes dialog

Root Cause

Both TuiPreviewDialog and TuiDialogCloseService listen for escape key events on the document:

  • TuiPreviewDialog: Uses (document:keydown.esc) host binding
  • TuiDialogCloseService: Filters escape events with !event.defaultPrevented check

The preview dialog handles the escape key but doesn't prevent event propagation, so the parent dialog also receives the same event and closes simultaneously.

Solution

Modified TuiPreviewDialog to prevent escape key event propagation:

Before:

host: {
    '(document:keydown.esc)': 'context.$implicit.complete()',
}

After:

host: {
    '(document:keydown.esc)': 'onEscape($event)',
}

onEscape(event: KeyboardEvent): void {
    event.preventDefault();    // Prevents default behavior
    event.stopPropagation();  // Stops event bubbling
    this.context.$implicit.complete();
}

Technical Details

  • The dialog close service already checks !event.defaultPrevented before handling escape keys
  • By calling preventDefault() in the preview dialog, we ensure the dialog service ignores the already-handled escape event
  • Creates a layered approach where the topmost dialog (preview) handles escape first

Expected Behavior After Fix

  • First escape: closes only the preview dialog, parent dialog remains open
  • Second escape: closes the parent dialog
  • Preview dialog standalone: works exactly as before
  • No regressions: all existing functionality preserved

Testing

  • Added focused test to verify escape key event propagation is prevented
  • All existing preview and dialog tests continue to pass
  • Build completes successfully for all libraries

Fixes #11401.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cloud.nx.app
    • Triggering command: node /home/REDACTED/work/taiga-ui/taiga-ui/node_modules/.bin/nx serve demo (dns block)
    • Triggering command: /opt/hostedtoolcache/node/20.19.4/x64/bin/node /home/REDACTED/work/taiga-ui/taiga-ui/.nx/cache/cloud/2507.21.8/lib/heartbeat/heartbeat-process.js (dns block)
    • Triggering command: node /home/REDACTED/work/taiga-ui/taiga-ui/node_modules/.bin/nx build demo (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copy link

lumberjack-bot bot commented Jul 24, 2025

Tests are running 🚀

Wait for workflow run with tests to finish ☕

@Copilot Copilot AI changed the title [WIP] 🐞 - Close preview at the same time as dialog 🐞 Fix escape key propagation in preview dialog to prevent closing parent dialog Jul 24, 2025
Copilot finished work on behalf of splincode July 24, 2025 13:31
@Copilot Copilot AI requested a review from splincode July 24, 2025 13:31
Copy link
Contributor Author

Copilot AI commented Jul 24, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cloud.nx.app
    • Triggering command: node /home/REDACTED/work/taiga-ui/taiga-ui/node_modules/.bin/nx run-many --target build --all --exclude=demo --output-style=stream --nxBail (dns block)
    • Triggering command: /opt/hostedtoolcache/node/20.19.4/x64/bin/node /home/REDACTED/work/taiga-ui/taiga-ui/.nx/cache/cloud/2507.21.8/lib/heartbeat/heartbeat-process.js (dns block)
    • Triggering command: node /home/REDACTED/work/taiga-ui/taiga-ui/node_modules/.bin/nx build kit (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@Copilot Copilot AI requested a review from splincode July 24, 2025 14:10
Copilot finished work on behalf of splincode July 24, 2025 14:10
@Copilot Copilot AI requested a review from splincode July 24, 2025 14:11
Copilot finished work on behalf of splincode July 24, 2025 14:23
@splincode splincode marked this pull request as ready for review July 24, 2025 14:29
@Copilot Copilot AI review requested due to automatic review settings July 24, 2025 14:29
@splincode splincode requested a review from a team as a code owner July 24, 2025 14:29
@splincode splincode requested review from MarsiBarsi and waterplea and removed request for a team July 24, 2025 14:29
@splincode splincode changed the title 🐞 Fix escape key propagation in preview dialog to prevent closing parent dialog fix(kit): escape key propagation in preview dialog to prevent closing parent dialog Jul 24, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug where pressing the Escape key in a preview dialog opened within a regular dialog would close both dialogs simultaneously instead of closing only the preview dialog first.

  • Modified the TuiPreviewDialog component to prevent escape key event propagation by adding preventDefault() and stopPropagation() calls
  • Added comprehensive Cypress tests to verify the layered escape key behavior works correctly
  • Ensures proper dialog nesting behavior where escape keys are handled by the topmost dialog first

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
projects/kit/components/preview/dialog/preview-dialog.component.ts Added onEscape method to handle escape key events with proper event propagation prevention
projects/demo-cypress/src/tests/preview-dialog.cy.ts Added new test file to verify escape key behavior in nested dialog scenarios

Copy link

nx-cloud bot commented Jul 24, 2025

View your CI Pipeline Execution ↗ for commit 05a8869

Command Status Duration Result
nx run-many --target test --all --output-style=... ✅ Succeeded 2m 20s View ↗

☁️ Nx Cloud last updated this comment at 2025-07-26 17:48:14 UTC

Copy link
Contributor

github-actions bot commented Jul 24, 2025

Visit the preview URL for this PR (updated for commit 05a8869):

https://taiga-previews-demo--pr11419-copilot-fix-11401-demo-6xdnd5gg.web.app

(expires Sun, 27 Jul 2025 17:21:49 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 73dddc3c665194f3e11f18c16aeb71af4c289c37

Copy link

bundlemon bot commented Jul 24, 2025

BundleMon

Files updated (1)
Status Path Size Limits
demo/browser/main.(hash).js
347.41KB (+26B +0.01%) +10%
Unchanged files (4)
Status Path Size Limits
demo/browser/vendor.(hash).js
260.83KB +10%
demo/browser/runtime.(hash).js
52.53KB +10%
demo/browser/styles.(hash).css
21.38KB +10%
demo/browser/polyfills.(hash).js
11.16KB +10%

Total files change +26B 0%

Groups updated (1)
Status Path Size Limits
demo/browser/*..js
9.55MB (+26B 0%) -

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

Copilot AI and others added 7 commits July 24, 2025 17:47
Co-authored-by: splincode <12021443+splincode@users.noreply.github.com>
Co-authored-by: splincode <12021443+splincode@users.noreply.github.com>
Co-authored-by: splincode <12021443+splincode@users.noreply.github.com>
Co-authored-by: splincode <12021443+splincode@users.noreply.github.com>
Co-authored-by: splincode <12021443+splincode@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@splincode splincode force-pushed the copilot/fix-11401 branch from 9132bb2 to 9a37711 Compare July 24, 2025 14:47
Copy link
Contributor

github-actions bot commented Jul 24, 2025

Playwright test results

passed  1244 passed
flaky  1 flaky
skipped  3 skipped

Details

report  Open report ↗︎
stats  1248 tests across 77 suites
duration  13 minutes, 34 seconds
commit  05a8869

Flaky tests

chromium › tests/kit/dropdown-hover/dropdown-hover.pw.spec.ts › DropdownHover › Examples › With DropdownMobile › Opens mobile version of dropdown on the 2nd time click

Skipped tests

chromium › tests/addon-mobile/mobile-dropdown/mobile-dropdown-with-textfield.pw.spec.ts › DropdownMobile for textfields › with legacy select
chromium › tests/core/dropdown/dropdown.pw.spec.ts › Dropdown › Esc -> Hosted Dropdown
chromium › tests/kit/input-number/input-number.pw.spec.ts › InputNumber › API › [prefix] & [postfix] props › non-erasable minus (as [prefix]) for [max] <= 0 › forbids to enter more minuses

Co-authored-by: splincode <12021443+splincode@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 26, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cloud.nx.app
    • Triggering command: node /home/REDACTED/work/taiga-ui/taiga-ui/node_modules/.bin/nx build kit (dns block)
    • Triggering command: /opt/hostedtoolcache/node/20.19.4/x64/bin/node /home/REDACTED/work/taiga-ui/taiga-ui/.nx/cache/cloud/2507.21.8/lib/heartbeat/heartbeat-process.js (dns block)
    • Triggering command: node /home/REDACTED/work/taiga-ui/taiga-ui/node_modules/.bin/nx run-many --target test --all --output-style=stream --testNamePattern=preview --passWithNoTests (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of splincode July 26, 2025 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

🐞 - Close preview at the same time as dialog
3 participants