From aacbce0938a4e161a9856e0a076a8ed90b418b41 Mon Sep 17 00:00:00 2001 From: Kumpal Madhiwala Date: Wed, 26 Mar 2025 12:55:28 -0400 Subject: [PATCH] [fix] - first aria-slider has different stepper when used manually vs with keyboard --- js/modules/enable-slider.js | 25 +++++++++++++++++-------- js/modules/es4/enable-slider.js | 25 +++++++++++++++++-------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/js/modules/enable-slider.js b/js/modules/enable-slider.js index b9601b16..48a97949 100755 --- a/js/modules/enable-slider.js +++ b/js/modules/enable-slider.js @@ -422,14 +422,19 @@ const enableSlider = function ( ); }); - $handle.addEventListener('touchstart', (e) => { - return this.handlePointerDown( - $handle, - $incrementor, - $decrementor, - e, - ); - }); + // Use passive: true for touchstart event listeners + $handle.addEventListener( + 'touchstart', + (e) => { + return this.handlePointerDown( + $handle, + $incrementor, + $decrementor, + e, + ); + }, + { passive: true }, + ); window.addEventListener('resize', this.handleResize); @@ -866,6 +871,10 @@ const enableSlider = function ( ); } + // Snap the value to the nearest increment + newVal = Math.round(newVal / this.inc) * this.inc; + + // Clamp the value within the allowed range newVal = Math.max(startVal, Math.min(newVal, stopVal)); this.positionHandle($handle, $handleButton, newVal); diff --git a/js/modules/es4/enable-slider.js b/js/modules/es4/enable-slider.js index 5997a440..5c67cb73 100755 --- a/js/modules/es4/enable-slider.js +++ b/js/modules/es4/enable-slider.js @@ -417,14 +417,19 @@ const enableSlider = function ( ); }); - $handle.addEventListener('touchstart', (e) => { - return this.handlePointerDown( - $handle, - $incrementor, - $decrementor, - e, - ); - }); + // Use passive: true for touchstart event listeners + $handle.addEventListener( + 'touchstart', + (e) => { + return this.handlePointerDown( + $handle, + $incrementor, + $decrementor, + e, + ); + }, + { passive: true }, + ); window.addEventListener('resize', this.handleResize); @@ -861,6 +866,10 @@ const enableSlider = function ( ); } + // Snap the value to the nearest increment + newVal = Math.round(newVal / this.inc) * this.inc; + + // Clamp the value within the allowed range newVal = Math.max(startVal, Math.min(newVal, stopVal)); this.positionHandle($handle, $handleButton, newVal);