Skip to content

Commit

Permalink
fix Primefaces primefaces#5044 Menu with popup prop passed doesnot cl…
Browse files Browse the repository at this point in the history
…ose on Escape keypress
  • Loading branch information
akshayantony55 committed Oct 5, 2023
1 parent e28dafe commit a7a423b
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 @@ -32331,6 +32331,14 @@
"type": "boolean",
"default": "false",
"description": "When enabled, it removes component related styles in the core."
},
{
"name": "closeOnEscape",
"optional": true,
"readonly": false,
"type": "boolean",
"default": "true",
"description": "Specifies if pressing escape key should hide the Menu Popup."
}
]
},
Expand Down
5 changes: 5 additions & 0 deletions components/lib/menu/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { OverlayService } from '../overlayservice/OverlayService';
import { Portal } from '../portal/Portal';
import { DomHandler, IconUtils, ObjectUtils, UniqueComponentId, ZIndexUtils, classNames, mergeProps } from '../utils/Utils';
import { MenuBase } from './MenuBase';
import { useOnEscapeKey } from '../../lib/hooks/Hooks';

export const Menu = React.memo(
React.forwardRef((inProps, ref) => {
Expand All @@ -26,6 +27,10 @@ export const Menu = React.memo(
const menuRef = React.useRef(null);
const targetRef = 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/menu/MenuBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ export const MenuBase = ComponentBase.extend({
transitionOptions: null,
onShow: null,
onHide: null,
children: undefined
children: undefined,
closeOnEscape: true
},
css: {
classes,
Expand Down
5 changes: 5 additions & 0 deletions components/lib/menu/menu.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ export interface MenuProps extends Omit<React.DetailedHTMLProps<React.HTMLAttrib
* @defaultValue false
*/
unstyled?: boolean;
/**
* Specifies if pressing escape key should hide the Menu Popup.
* @defaultValue true
*/
closeOnEscape?: boolean | undefined;
}

/**
Expand Down

0 comments on commit a7a423b

Please sign in to comment.