@@ -24,7 +24,7 @@ import {
2424} from "@posthog/quill" ;
2525import { Badge } from "@posthog/ui/primitives/Badge" ;
2626import { openUrlInBrowser } from "@posthog/ui/utils/browser" ;
27- import { Fragment , useEffect , useRef , useState } from "react" ;
27+ import { Fragment , useRef , useState } from "react" ;
2828
2929export interface ReasoningLevelOption {
3030 value : string ;
@@ -230,27 +230,24 @@ export function ReasoningSliderFace({
230230 const matchedIndex = stops . findIndex ( ( stop ) => stop . key === currentKey ) ;
231231 const activeIndex =
232232 matchedIndex >= 0 ? matchedIndex : Math . floor ( ( stops . length - 1 ) / 2 ) ;
233- // Continuous position so the thumb tracks the pointer fluidly; the nearest
234- // notch is applied live and the thumb snaps to it on release.
235- const [ position , setPosition ] = useState < number > ( activeIndex ) ;
236- const draggingRef = useRef ( false ) ;
233+ // Continuous drag position so the thumb tracks the pointer fluidly; outside
234+ // a drag the thumb derives from the current selection, so releasing snaps
235+ // it to the notch the live-applied selection landed on.
236+ const [ dragPosition , setDragPosition ] = useState < number | null > ( null ) ;
237+ const position = dragPosition ?? activeIndex ;
237238 const nearestIndex = Math . min (
238239 stops . length - 1 ,
239240 Math . max ( 0 , Math . round ( position ) ) ,
240241 ) ;
241242
242- useEffect ( ( ) => {
243- if ( ! draggingRef . current ) setPosition ( activeIndex ) ;
244- } , [ activeIndex ] ) ;
245-
246243 const applyNotch = ( notch : number ) => {
247244 const stop = stops [ notch ] ;
248245 if ( stop && stop . key !== currentKey ) onSelect ( stop . key ) ;
249246 } ;
250247
251248 const nudge = ( delta : number ) => {
252249 const next = Math . min ( stops . length - 1 , Math . max ( 0 , nearestIndex + delta ) ) ;
253- setPosition ( next ) ;
250+ setDragPosition ( null ) ;
254251 applyNotch ( next ) ;
255252 } ;
256253
@@ -348,21 +345,18 @@ export function ReasoningSliderFace({
348345 onValueChange = { ( next : number | readonly number [ ] ) => {
349346 const raw = Array . isArray ( next ) ? next [ 0 ] : next ;
350347 if ( typeof raw !== "number" ) return ;
351- draggingRef . current = true ;
352- setPosition ( raw ) ;
348+ setDragPosition ( raw ) ;
353349 // Applied per notch crossing so the trigger pill tracks the drag.
354350 applyNotch ( Math . round ( raw ) ) ;
355351 } }
356352 onValueCommitted = { ( next : number | readonly number [ ] ) => {
357353 const raw = Array . isArray ( next ) ? next [ 0 ] : next ;
358- draggingRef . current = false ;
359- if ( typeof raw !== "number" ) return ;
360- const notch = Math . min (
361- stops . length - 1 ,
362- Math . max ( 0 , Math . round ( raw ) ) ,
363- ) ;
364- setPosition ( notch ) ;
365- applyNotch ( notch ) ;
354+ if ( typeof raw === "number" ) {
355+ applyNotch (
356+ Math . min ( stops . length - 1 , Math . max ( 0 , Math . round ( raw ) ) ) ,
357+ ) ;
358+ }
359+ setDragPosition ( null ) ;
366360 } }
367361 />
368362 < div className = "-translate-y-1/2 pointer-events-none absolute inset-x-2 top-1/2 flex justify-between" >
0 commit comments