CompareSlider
Before/after slider to compare two layers of content
Source
Package
Usage
CompareSlider displays two layers in the same box with a draggable divider between them,
for example to compare two versions of an image. The before layer is displayed on the left
of the divider, the after layer on the right:


Compare any content
before and after accept any React node. Both layers fill the container,
make sure they have the same dimensions:
After
New design
Before
Old design
Vertical orientation
Set orientation="vertical" to move the divider vertically:


Controlled
Set position and onPositionChange props to control the divider position.
The position is a number between 0 and 100:


Divider position: 30%
Change position on hover
Set changePositionOnHover to move the divider with the pointer instead of dragging:


Custom handle
Use the handle prop to replace the default divider handle with any React node:


Set withHandle={false} to hide the handle, the divider line stays interactive:
Container size
CompareSlider takes the full width of its parent and has no intrinsic height. Set the height
with h prop or an aspect-ratio. If the parent does not constrain the width, for example a flex
container, set w or maw as well. Make both layers fill the box:
Transition
Set transition to true or a duration in milliseconds to animate keyboard and controlled position changes.
Dragging and changePositionOnHover move the divider immediately. Click the button to see the transition:
Disabled
Set disabled to lock the divider:


Accessibility
Set aria-label to describe what the handle compares:
Keyboard interactions
In vertical orientation, ArrowUp
decreases the position and ArrowDown increases it: