function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Surender reddy SalukutiSurender reddy Salukuti 

How can i close popup when i clicked on ESC button on keyboard in salesforce lightning

HI ,

How can i close popup when i click ESC button on Key boar in salesforce lightning .

Please provie me solution 

Thank you
Surender reddy
 
SwethaSwetha (Salesforce Developers) 
HI Surender,
Can you elaborate on your ask?Can you share a screenshot so we can understand better.Thanks
Marzorati ClaudioMarzorati Claudio
Hi Surender,
you must caugth the event fired and control the keyCode.
For the escape keyCode = 27 (https://keycode.info/)

User-added image

For example assuming you are in a lwc, you can do something like that
 
handleKeyUp(evt) {
	this.isLoaded = !this.isLoaded;

	const isEnterKey = evt.keyCode === 27;
	if (isEnterKey) {
		// close function
	}
}
and this the front end where you fire the event
<div onkeyup={handleKeyUp}>
	<lightning-input
			name="enter-search"
			label="Premi 'invio' per iniziare la ricerca"
			type="search"
	></lightning-input>
</div>

The same can be applied for your need.

Let me know if I have solved your problem
Surender reddy SalukutiSurender reddy Salukuti
Hi Swetha ,

 My scenario When we open any Custom popup we need to close that popup if using ESC button in keyboard how we will do that functionality using slesforce lightning .

Thank you
Surener reddy 
Surender reddy SalukutiSurender reddy Salukuti

Hi Marzorati Claudio,

 Can you provide me brief explanation how we need to use  it will be hepl full for me

Thank you 
Surender Reddy
Marzorati ClaudioMarzorati Claudio
Hi Surender,

here an example: https://developer.salesforce.com/docs/component-library/tools/playground/vQ70xGgH-/3/edit
Press ESC button when popup appear. This is what you asked.

The same could be done for Aura Component.

Claudio