Skip to content

Commit

Permalink
fix Primefaces primefaces#4961 SlideMenu: SlideMenu with popup prop p…
Browse files Browse the repository at this point in the history
…assed doesnot close on Escape keypress.
  • Loading branch information
akshayantony55 committed Sep 25, 2023
1 parent 7e2f278 commit a9187e8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
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

0 comments on commit a9187e8

Please sign in to comment.