- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 21
 
V4 Improvements #170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
V4 Improvements #170
Conversation
…ercentages for clip path
…logic to container items
| 
           The latest updates on your projects. Learn more about Vercel for GitHub. 
  | 
    
          
commit:   | 
    
…t needed because of new css vars logic
…r keyboard increment basis
BREAKING CHANGE: Unitless values are no longer supported, raw numbers like `20` must be passed as `20px`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors slider positioning to rely on CSS variables, removes the resize observer, and extends boundsPadding to accept arbitrary CSS units.
- Replaced manual DOM clipping and resize observer with a CSS variable–based approach (
currentPositionandboundsPadding). - Updated the 
boundsPaddingprop fromnumbertostring, enabling any CSS unit. - Simplified event handling and merged imperative position updates into a single 
setPositioncallback. 
Reviewed Changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description | 
|---|---|
| lib/src/utils.ts | Consolidated imports; removed useResizeObserver; adjusted hooks for undefined targets. | 
| lib/src/types.ts | Changed several interfaces to type; updated boundsPadding to string. | 
| lib/src/consts.ts | Added ReactCompareSliderCssVars for CSS variable names. | 
| lib/src/ReactCompareSlider.tsx | Rewrote position logic to use CSS vars; removed resize observer; centralized setPosition. | 
| lib/src/Container.tsx | Updated clipping to use CSS vars; removed explicit position prop on handle. | 
| lib/src/useReactCompareSliderRef.ts | Minor formatting change to console.warn. | 
| docs/**/* | Adjusted stories and README to reflect boundsPadding: string; cleaned up formatting. | 
| .vscode/settings.json | Increased ruler width to 110. | 
| .prettierrc.js, .editorconfig | Updated line length settings to 110. | 
| .github/workflows/publish-preview.yml | Bumped actions versions and simplified install command. | 
Comments suppressed due to low confidence (3)
lib/src/types.ts:50
- The 
keyboardIncrementprop still accepts onlynumberaccording to the type definitions, but the implementation now supports string units; update its type tostring | numberand adjust documentation accordingly. 
  boundsPadding?: string;
README.md:78
- Update the description for 
boundsPaddingto reflect that it accepts any CSS unit (e.g.,px,%,rem), not just pixels. 
| [`boundsPadding`](https://react-compare-slider.vercel.app/?path=/story/demos--bounds-padding)                   | `string`                     |   | `0%`           | Padding to limit the slideable bounds in pixels on the X-axis (landscape) or Y-axis (portrait).
lib/src/Container.tsx:95
- Removing the default 
aria-valuenowattribute could cause a missing initial slider value in assistive technologies. Ensure an initialaria-valuenowis set, for example by passing the initial position prop or adding a default attribute. 
        aria-valuemax={100}
| : (keyboardIncrement / width) * 100; | ||
| const incrementPercentage = | ||
| typeof keyboardIncrement === 'string' | ||
| ? parseFloat(keyboardIncrement) | 
    
      
    
      Copilot
AI
    
    
    
      Jun 25, 2025 
    
  
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parsing keyboardIncrement strings only via parseFloat treats any unit as a percentage, so passing pixel values (e.g. '20px') will not convert correctly. Consider detecting unit suffixes ('%', 'px', etc.) and converting accordingly to percent or pixel-based increments.
| ? parseFloat(keyboardIncrement) | |
| ? (() => { | |
| const match = keyboardIncrement.match(/^([\d.]+)(px|%)?$/); | |
| if (!match) { | |
| console.warn('Invalid keyboardIncrement value:', keyboardIncrement); | |
| return 0; // Default to 0 if the value is invalid | |
| } | |
| const [, value, unit] = match; | |
| const numericValue = parseFloat(value); | |
| if (unit === 'px') { | |
| return (numericValue / width) * 100; // Convert pixels to percentage | |
| } | |
| return numericValue; // Assume percentage if unit is '%' or undefined | |
| })() | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 47 out of 48 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Perf
Feat
boundsPaddingsupport any CSS unitkeyboardIncrementsupport any CSS unitStyle
CI
Checks
boundsPaddingtests