@@ -190,28 +190,35 @@ export default function useOffset(
190190 return ( pushable === null && dist === 0 ) || ( typeof pushable === 'number' && dist < pushable ) ;
191191 } ;
192192
193+ // Get the minimum boundary for a handle considering disabled handles
194+ const getHandleMinBound = ( values : number [ ] , handleIndex : number ) : number => {
195+ if ( ! isHandleDisabled ) return min ;
196+ for ( let i = handleIndex - 1 ; i >= 0 ; i -= 1 ) {
197+ if ( isHandleDisabled ( i ) ) {
198+ return values [ i ] + ( typeof pushable === 'number' ? pushable : 0 ) ;
199+ }
200+ }
201+ return min ;
202+ } ;
203+
204+ // Get the maximum boundary for a handle considering disabled handles
205+ const getHandleMaxBound = ( values : number [ ] , handleIndex : number ) : number => {
206+ if ( ! isHandleDisabled ) return max ;
207+ for ( let i = handleIndex + 1 ; i < values . length ; i += 1 ) {
208+ if ( isHandleDisabled ( i ) ) {
209+ return values [ i ] - ( typeof pushable === 'number' ? pushable : 0 ) ;
210+ }
211+ }
212+ return max ;
213+ } ;
214+
193215 // Values
194216 const offsetValues : OffsetValues = ( values , offset , valueIndex , mode = 'unit' ) => {
195217 const nextValues = values . map < number > ( formatValue ) ;
196218 const originValue = nextValues [ valueIndex ] ;
197219
198- let minBound = min ;
199- let maxBound = max ;
200-
201- if ( isHandleDisabled ) {
202- for ( let i = valueIndex - 1 ; i >= 0 ; i -= 1 ) {
203- if ( isHandleDisabled ( i ) ) {
204- minBound = nextValues [ i ] ;
205- break ;
206- }
207- }
208- for ( let i = valueIndex + 1 ; i < nextValues . length ; i += 1 ) {
209- if ( isHandleDisabled ( i ) ) {
210- maxBound = nextValues [ i ] ;
211- break ;
212- }
213- }
214- }
220+ const minBound = getHandleMinBound ( nextValues , valueIndex ) ;
221+ const maxBound = getHandleMaxBound ( nextValues , valueIndex ) ;
215222
216223 const nextValue = offsetValue ( nextValues , offset , valueIndex , mode ) ;
217224 nextValues [ valueIndex ] = nextValue ;
@@ -253,6 +260,10 @@ export default function useOffset(
253260 while ( needPush ( nextValues [ i ] - nextValues [ i - 1 ] ) && changed ) {
254261 ( { value : nextValues [ i ] , changed } = offsetChangedValue ( nextValues , 1 , i ) ) ;
255262 }
263+ // Apply boundary constraint to pushed handle
264+ if ( isHandleDisabled ) {
265+ nextValues [ i ] = Math . min ( nextValues [ i ] , getHandleMaxBound ( nextValues , i ) ) ;
266+ }
256267 }
257268
258269 // Start values (skip disabled handles)
@@ -264,6 +275,10 @@ export default function useOffset(
264275 while ( needPush ( nextValues [ i ] - nextValues [ i - 1 ] ) && changed ) {
265276 ( { value : nextValues [ i - 1 ] , changed } = offsetChangedValue ( nextValues , - 1 , i - 1 ) ) ;
266277 }
278+ // Apply boundary constraint to pushed handle
279+ if ( isHandleDisabled ) {
280+ nextValues [ i - 1 ] = Math . max ( nextValues [ i - 1 ] , getHandleMinBound ( nextValues , i - 1 ) ) ;
281+ }
267282 }
268283
269284 // >>>>> Revert back to safe push range
@@ -276,6 +291,10 @@ export default function useOffset(
276291 while ( needPush ( nextValues [ i ] - nextValues [ i - 1 ] ) && changed ) {
277292 ( { value : nextValues [ i - 1 ] , changed } = offsetChangedValue ( nextValues , - 1 , i - 1 ) ) ;
278293 }
294+ // Apply boundary constraint to pushed handle
295+ if ( isHandleDisabled ) {
296+ nextValues [ i - 1 ] = Math . max ( nextValues [ i - 1 ] , getHandleMinBound ( nextValues , i - 1 ) ) ;
297+ }
279298 }
280299
281300 // Start to End (skip disabled handles)
@@ -287,6 +306,10 @@ export default function useOffset(
287306 while ( needPush ( nextValues [ i + 1 ] - nextValues [ i ] ) && changed ) {
288307 ( { value : nextValues [ i + 1 ] , changed } = offsetChangedValue ( nextValues , 1 , i + 1 ) ) ;
289308 }
309+ // Apply boundary constraint to pushed handle
310+ if ( isHandleDisabled ) {
311+ nextValues [ i + 1 ] = Math . min ( nextValues [ i + 1 ] , getHandleMaxBound ( nextValues , i + 1 ) ) ;
312+ }
290313 }
291314 }
292315
0 commit comments