fix(client/interface): reset nui focus on alert (#192)

This commit is contained in:
Hepic Greg
2022-12-30 11:16:33 +01:00
committed by GitHub
parent a2772a87b4
commit 86d66b85c1

View File

@@ -1,4 +1,10 @@
local alert = nil
local keepInput = IsNuiFocusKeepingInput()
local function resetFocus()
SetNuiFocus(false, false)
SetNuiFocusKeepInput(keepInput)
end
---@class AlertDialogProps
---@field header string;
@@ -13,7 +19,10 @@ function lib.alertDialog(data)
if alert then return end
alert = promise.new()
keepInput = IsNuiFocusKeepingInput()
SetNuiFocus(true, true)
SetNuiFocusKeepInput(false)
SendNUIMessage({
action = 'sendAlert',
data = data
@@ -26,7 +35,7 @@ function lib.closeAlertDialog()
if not alert then return end
alert:resolve(nil)
alert = nil
SetNuiFocus(false, false)
resetFocus()
SendNUIMessage({
action = 'closeAlertDialog'
})
@@ -35,10 +44,10 @@ end
RegisterNUICallback('closeAlert', function(data, cb)
cb(1)
SetNuiFocus(false, false)
resetFocus()
local promise = alert
alert = nil
promise:resolve(data)
end)
RegisterNetEvent('ox_lib:alertDialog', lib.alertDialog)
RegisterNetEvent('ox_lib:alertDialog', lib.alertDialog)