Skip to content

Comments

fix(contextual-menu): allow Escape key to close menu inside modal (#1…#1315

Open
NamanMehta16 wants to merge 1 commit intocanonical:mainfrom
NamanMehta16:1305-fix-esc-modal
Open

fix(contextual-menu): allow Escape key to close menu inside modal (#1…#1315
NamanMehta16 wants to merge 1 commit intocanonical:mainfrom
NamanMehta16:1305-fix-esc-modal

Conversation

@NamanMehta16
Copy link

…305)

Done

  • ContextualMenu now closes when pressing Escape inside a Modal.
  • Added handleKeyDown logic and ensured focus handling works with portals.
  • Updated tests to cover ESC key behavior inside Modals.

QA

Pinging @canonical/react-library-maintainers for a review.

Storybook

To see rendered examples of all react-components, run:

yarn start

QA in your project

from react-components run:

yarn build
npm pack

Install the resulting tarball in your project with:

yarn add <path-to-tarball>

QA steps

  • Open a Modal with a ContextualMenu inside.
  • Open the menu and press ESC.
  • Ensure the menu closes and focus returns to the trigger button.

Percy steps

  • No visual changes expected.

Fixes

Fixes: # .

@webteam-app
Copy link

NamanMehta16 is not a collaborator of the repo

Copy link
Contributor

@edlerd edlerd left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution, one clarifying question below.

Copy link
Contributor

@edlerd edlerd left a comment

Choose a reason for hiding this comment

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

Code LGTM.

The comments are a bit confusing. Maybe remove or rephrase to communicate better the reason for the code below them.

Comment on lines +218 to +219
// Ensure portal is closed when isOpen becomes false,
// even if keydown handler is not reached
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Ensure portal is closed when isOpen becomes false,
// even if keydown handler is not reached

I don't understand how the comment relates to the code below.

}
};

// capture phase helps when modal stops propagation
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// capture phase helps when modal stops propagation

Not sure what this is supposed to mean. It seems confusing to me.

@edlerd
Copy link
Contributor

edlerd commented Feb 16, 2026

Thanks for the update. This looks mostly good to merge. Just some thoughts on the comments above and some linter failures below. Please take a look.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants