Skip to content

Commit

Permalink
fix + document unmount during slide behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
sircfenner committed Jun 22, 2024
1 parent b4f3022 commit 25a825a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/Components/Slider.luau
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
```
Optionally, an `OnCompleted` callback prop can be provided. This will be called with the latest
value of the Slider when sliding is finished. It is also called if the component becomes Disabled
via props while a slide is in progress.
value of the Slider when sliding is finished. It is also called if, while sliding is in progress,
the component becomes Disabled via props or is unmounted.
Two further props can optionally be provided:
1. `Border` determines whether a border is drawn around the component.
Expand All @@ -51,6 +51,8 @@ local React = require("@pkg/@jsdotlua/react")

local CommonProps = require("../CommonProps")
local Constants = require("../Constants")

local useFreshCallback = require("../Hooks/useFreshCallback")
local useMouseDrag = require("../Hooks/useMouseDrag")
local useTheme = require("../Hooks/useTheme")

Expand Down Expand Up @@ -110,11 +112,11 @@ local function Slider(props: SliderProps)
end
end

local dragEndedCallback = function()
local dragEndedCallback = useFreshCallback(function()
if props.OnCompleted then
props.OnCompleted(props.Value)
end
end
end, { props.Value, props.OnCompleted } :: { unknown })

local dragDeps = { props.Value, props.Min, props.Max, props.Step, props.OnCompleted, onChanged } :: { unknown }
local drag = useMouseDrag(dragCallback, dragDeps, nil, dragEndedCallback)
Expand Down
2 changes: 1 addition & 1 deletion src/Hooks/useMouseDrag.luau
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ local function useMouseDrag(
moveConnection.current:Disconnect()
moveConnection.current = nil
end
if onEndedCallback then
if onEndedCallback and holding.current == true then
onEndedCallback()
end
end
Expand Down

0 comments on commit 25a825a

Please sign in to comment.