mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
refactor(client/interface): nui focus tweaks
Add helper functions to set nui focus and restore previous input state. Ensure focus is reset before triggering responses (promises/callbacks).
This commit is contained in:
@@ -1,10 +1,4 @@
|
||||
local alert = nil
|
||||
local keepInput = IsNuiFocusKeepingInput()
|
||||
|
||||
local function resetFocus()
|
||||
SetNuiFocus(false, false)
|
||||
SetNuiFocusKeepInput(keepInput)
|
||||
end
|
||||
|
||||
---@class AlertDialogProps
|
||||
---@field header string;
|
||||
@@ -19,10 +13,9 @@ end
|
||||
---@return 'cancel' | 'confirm' | nil
|
||||
function lib.alertDialog(data)
|
||||
if alert then return end
|
||||
|
||||
alert = promise.new()
|
||||
|
||||
keepInput = IsNuiFocusKeepingInput()
|
||||
|
||||
lib.setNuiFocus(false)
|
||||
SetNuiFocus(true, true)
|
||||
SetNuiFocusKeepInput(false)
|
||||
SendNUIMessage({
|
||||
@@ -35,20 +28,24 @@ end
|
||||
|
||||
function lib.closeAlertDialog()
|
||||
if not alert then return end
|
||||
alert:resolve(nil)
|
||||
alert = nil
|
||||
resetFocus()
|
||||
|
||||
lib.resetNuiFocus()
|
||||
SendNUIMessage({
|
||||
action = 'closeAlertDialog'
|
||||
})
|
||||
alert:resolve(nil)
|
||||
|
||||
alert = nil
|
||||
end
|
||||
|
||||
|
||||
RegisterNUICallback('closeAlert', function(data, cb)
|
||||
cb(1)
|
||||
resetFocus()
|
||||
lib.resetNuiFocus()
|
||||
|
||||
local promise = alert
|
||||
alert = nil
|
||||
|
||||
promise:resolve(data)
|
||||
end)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user