Skip to content

Conversation

@jashwanthb9
Copy link

@jashwanthb9 jashwanthb9 commented Dec 9, 2025

Problem

NxModal registers a cancel event handler that fails to distinguish between cancel events from the dialog itself versus those from descendant elements. File input elements (<input type="file">) also fire cancel events when users cancel file selection or select the same file again, causing the modal to close unexpectedly.

This affects any modal containing file inputs, such as the SBOM Import Modal.

Root Cause

The AbstractDialog.tsx component's cancel event listener was directly calling onCancel for all cancel events without checking the event source. Cancel events bubble up from child elements, triggering the modal to close when it shouldn't.

Solution

Added event target validation in the cancel event handler to filter events:

  • Only processes cancel events where event.target === dialog
  • Ignores cancel events bubbling up from descendant elements like file inputs
  • Preserves intended behavior for ESC key and dialog-level cancel actions

Changes Made

Modified lib/components/NxModal/AbstractDialog.tsx:

  • Wrapped the cancel event handler in a filter function
  • Added event.target === dialog check before calling onCancel
  • Updated both addEventListener and removeEventListener to use the wrapper function

Testing

Tested scenarios:

  • ✅ Modal no longer closes when file selection is canceled
  • ✅ Modal no longer closes when same file is selected again
  • ✅ Modal still closes properly on ESC key press
  • ✅ Modal still closes on explicit cancel button click

Steps to Test:

  1. Open any modal containing a file input (e.g., SBOM Import Modal)
  2. Click "Choose File" and cancel the file picker → Modal should remain open
  3. Click "Choose File", select a file, then select the same file again → Modal should remain open
  4. Press ESC key → Modal should close
  5. Click cancel/close button → Modal should close

Jira

Jira ticket(s) link: https://sonatype.atlassian.net/browse/CLM-36834

PR Checklist

  • I have tested the changes locally
  • I have verified no regressions in modal behavior
  • I have run the build successfully
  • Changes target the 12.x-backports branch

EBermudez88 and others added 30 commits August 16, 2023 13:10
…nChange_signature

Update NxFormSelect onChange signature- RSC-1719
Co-authored-by: Ross Pokorny <rpokorny@sonatype.com>
…me_for_NxCollapsibleItemsSelect

Support JSX option name for NxCollapsibleItemsSelect - RSC-1283
RSC 13.0.0

React 18 - RSC-1550
Update NxFormSelect onChange signature - RSC-1719
Support JSX option name for NxCollapsibleItemsSelect - RSC-1283
rpokorny and others added 21 commits June 26, 2025 08:22
Update visualtest instructions with new docker container
Upgrade all potentially-relevant packages for CVE-2025-55182
- Add event.target check in cancel event handler
- Prevents modal from closing when file input cancel events bubble up
- Only handle cancel events originating from the dialog itself
@jashwanthb9 jashwanthb9 requested review from a team and rpokorny December 9, 2025 07:44
@rpokorny
Copy link
Contributor

rpokorny commented Dec 9, 2025

Consider this optional since you're new, but ideally there would be a functional test (in the visual-tests suite) that validates this fix. This would require an example of a modal which contains a file upload to be added to the gallery as well, as that would be what the test operates on.

Also, note that the build for this repo requires that you bump the version numbers in the package.json files before the build will pass, this is so that when it merges to main a new release can be generated automatically. See the readme for instructions on the best commands to run to perform that version bump.

@rpokorny
Copy link
Contributor

rpokorny commented Dec 9, 2025

I notice that this branch was unfortunately based off of, and is being merged into, the wrong target branch. Since the goal here is the fix an issue seen in IQ, and IQ is still on RSC 12, you need to re-create this branch off of the 12.x-backports branch, and adjust the PR to have that branch as its target.

After the PR is complete and merged to 12.x-backports, and jenkins build of that branch will result in a new 12.x release of RSC. Then, we will merge 12.x-backports into main in order to also release a new version of RSC 14.x with this fix. The idea is that any fixes or new features added to 12.x should also be added to 14.x, but not necessarily vice-versa.

@jashwanthb9 jashwanthb9 changed the base branch from main to 12.x-backports December 10, 2025 06:44
@jashwanthb9 jashwanthb9 deleted the fix/modal-cancel-event-filter branch December 10, 2025 06:56
@jashwanthb9
Copy link
Author

Closing this PR as it was targeting the wrong base branch (main instead of 12.x-backports).

Since IQ uses RSC 12.x, the fix needs to be merged into 12.x-backports first, then propagated to main for the 14.x release.

New PR created: [link to your new PR]

Jira: https://sonatype.atlassian.net/browse/CLM-36834

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.