@@ -29,6 +29,7 @@ import { createBitsAttrs, boolToStr, boolToEmptyStrOrUndef } from "$lib/internal
2929import { kbd } from "$lib/internal/kbd.js" ;
3030import { isElementOrSVGElement } from "$lib/internal/is.js" ;
3131import { isValidIndex } from "$lib/internal/arrays.js" ;
32+ import { SvelteResizeObserver } from "$lib/internal/svelte-resize-observer.svelte.js" ;
3233import type {
3334 BitsKeyboardEvent ,
3435 OnChangeFn ,
@@ -64,6 +65,7 @@ abstract class SliderBaseRootState {
6465 readonly opts : SliderBaseRootStateOpts ;
6566 readonly attachment : RefAttachment ;
6667 isActive = $state ( false ) ;
68+ #layoutVersion = $state ( 0 ) ;
6769 readonly direction : "rl" | "lr" | "tb" | "bt" = $derived . by ( ( ) => {
6870 if ( this . opts . orientation . current === "horizontal" ) {
6971 return this . opts . dir . current === "rtl" ? "rl" : "lr" ;
@@ -82,8 +84,13 @@ abstract class SliderBaseRootState {
8284 this . opts = opts ;
8385 this . attachment = attachRef ( opts . ref ) ;
8486 this . domContext = new DOMContext ( this . opts . ref ) ;
87+ new SvelteResizeObserver ( ( ) => this . opts . ref . current , this . #handleLayoutChange) ;
8588 }
8689
90+ #handleLayoutChange = ( ) : void => {
91+ this . #layoutVersion += 1 ;
92+ } ;
93+
8794 isThumbActive ( _index : number ) {
8895 return this . isActive ;
8996 }
@@ -100,6 +107,8 @@ abstract class SliderBaseRootState {
100107 } ;
101108
102109 getThumbScale = ( ) : [ number , number ] => {
110+ void this . #layoutVersion;
111+
103112 // If trackPadding is explicitly set, use it directly instead of calculating from thumb size
104113 const trackPadding = this . opts . trackPadding ?. current ;
105114 if ( trackPadding !== undefined && trackPadding > 0 ) {
0 commit comments