Hi
I need to displaying a <p-dialog> that contains two <p-dropdown> boxes. The user can enter a number in one of those boxes, then hit the Enter key to close the dialog and apply this value. Beside this he can hit anytime the Escape key to close the dialog without applying the changes (pretty intuitive). Is this somehow possible (may be without any 'Apply'and 'Close' buttons in the dialog)?
Btw.: What is the intent of the event parameter in onHide(). I tried to pass the $event into my onHide() method, but the object is always empty. No matter how I close the dialog (ESC / toggle visible property).
How to close dialog with Enter key
Use a host listener to listen for keyboard events.
Code: Select all
@HostListener("window:keyup", ["$event"])
keyEvent(event: KeyboardEvent) {
console.log(event);
// ESC key
if (event.keyCode === 27) {
// your logic;
}
}
-
- Information
-
Who is online
Users browsing this forum: No registered users and 11 guests