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 Primefaces #4961 SlideMenu: SlideMenu with popup prop passed doesnot close on Escape keypress. #4962

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions components/doc/common/apidoc/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -42300,6 +42300,14 @@
"default": "false",
"description": "Defines if menu would displayed as a popup."
},
{
"name": "closeOnEscape",
"optional": true,
"readonly": false,
"type": "boolean",
"default": "true",
"description": "Specifies if pressing escape key should hide the SlideMenu Popup."
},
{
"name": "pt",
"optional": true,
Expand Down
5 changes: 5 additions & 0 deletions components/lib/slidemenu/SlideMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Portal } from '../portal/Portal';
import { DomHandler, IconUtils, UniqueComponentId, ZIndexUtils, mergeProps } from '../utils/Utils';
import { SlideMenuBase } from './SlideMenuBase';
import { SlideMenuSub } from './SlideMenuSub';
import { useOnEscapeKey } from '../../lib/hooks/Hooks';

export const SlideMenu = React.memo(
React.forwardRef((inProps, ref) => {
Expand All @@ -34,6 +35,10 @@ export const SlideMenu = React.memo(
const backward = React.useRef(null);
const slideMenuContent = React.useRef(null);

useOnEscapeKey(targetRef, props.popup && props.closeOnEscape, (event) => {
hide(event);
});

const [bindOverlayListener, unbindOverlayListener] = useOverlayListener({
target: targetRef,
overlay: menuRef,
Expand Down
3 changes: 2 additions & 1 deletion components/lib/slidemenu/SlideMenuBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ export const SlideMenuBase = ComponentBase.extend({
submenuIcon: null,
transitionOptions: null,
viewportHeight: 175,
children: undefined
children: undefined,
closeOnEscape: true
},
css: {
classes,
Expand Down
5 changes: 5 additions & 0 deletions components/lib/slidemenu/slidemenu.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ export interface SlideMenuProps extends Omit<React.DetailedHTMLProps<React.HTMLA
* @defaultValue 175
*/
viewportHeight?: number | undefined;
/**
* Specifies if pressing escape key should hide the SlideMenu Popup.
* @defaultValue true
*/
closeOnEscape?: boolean | undefined;
/**
* Callback to invoke when a popup menu is shown.
* @param {React.SyntheticEvent} event - Browser event.
Expand Down