Skip to content
Munif Tanjim edited this page Jun 22, 2023 · 3 revisions

Strategies for closing the Popup

Depending on what your use case is, you probably want to setup some way for the popup window to close itself. Below are some common strategies. All of the examples below assume you have created a Popup window already, such as in the example at lua/nui/popup.

NOTE: If the popup is not cleaned up properly with popup:unmount() when the window is closed, you may get undesired behavior such as an orphaned window border.

Close on Lost Focus

This example will close the popup when it loses focus for any reason, including an explicit close or the user switching to another window:

  popup:mount()

  popup:on("BufLeave", function()
    popup:unmount()
  end, { once = true })
Clone this wiki locally