Carousel
Notes
Allows for an easy way to add elements to a carousel. It was built with accessibility in mind and is fully navigable by tabbing and left/right keys.
Props
- areAllSlidesCurrentlyVisible
func
[() => {}]
Optional function which receives a boolean representing whether all children fit in the carousel in the current viewport; runs on every re-render
- childContainer
elementType
Optional component that will be used to wrap the visible carousel slides. Useful for injecting some custom CSS.
- children
node
- carouselClassName
string
This class(es) to be used for the main Carousel component.
- containerClassName
string
This class(es) will be used to style the container of the Carousel component.
- sliderClassName
string
This class(es) will be used to style the slide container in the Carousel component.
- controlClassName
string
This class(es) will modify the pagination control styling. A helper class
isActive
is added whenever a dot is active. - pagerClassName
string
This class(es) will modify the pager buttons control styling.
- easingFunction
oneOf('linear', 'easeInQuad', 'easeOutQuad', 'easeInOutQuad', 'easeInCubic', 'easeOutCubic', 'easeInOutCubic', 'easeInQuart', 'easeOutQuart', 'easeInOutQuart', 'easeInQuint', 'easeOutQuint', 'easeInOutQuint', 'easeInSine', 'easeOutSine', 'easeInOutSine', 'easeInExpo', 'easeOutExpo', 'easeInOutExpo', 'easeInCirc', 'easeOutCirc', 'easeInOutCirc', 'easeInElastic', 'easeOutElastic', 'easeInOutElastic', 'easeInBack', 'easeOutBack', 'easeInOutBack', 'easeInBounce', 'easeOutBounce', 'easeInOutBounce')
['easeOutQuad']
The easing function to use for the slide animation. See easings.net for examples.
- focusOnChangeSlide
bool
[false]
If true, sets focus on the first tabbable element in the current slide when carousel advances or reverses.
- onSlideChange
func
[() => {}]
Will get called the new slide index everytime it changes.
- globalKeyBindings
bool
[false]
If true, it allows the user to control the carousel with the left/right keys
- handleTouch
bool
[true]
Flag indicating that the carousel should move on touch events. Disable to prevent touch screen users from swiping to change carousel pages.
- id
string
- initialCurrentSlide
number
[0]
- labelledById
string
Id of the element describing the purpose of the carousel. Will be used in conjunction with aria-describedby attribute to create an accessible description of how to interact with the carousel.
- loading
bool
[false]
- messagesshape {ariaDescription
string
ariaLabelstring
ariaLabelNextstring
ariaLabelPrevstring
}ariaLabelPagesfunc
[{}]
Aria labels needed to describe different parts of the carousel.
This prop should be an object with the following keys:
ariaDescription
: describes the overall functionality of the carousel.ariaLabel
: labels the carousel.ariaLabelNext
label for the 'Next Page' button.ariaLabelPrev
label for the 'Previous Page' button.ariaLabelPages
this is a function that will label all the page control 'dots'. It will be passed a page number and it must return a string, e.g.num => `go to page ${num}`
.
- inactiveSlideClassName
string
Optional class applied to slides that are not currently visible.
- showPagerButtons
bool
[true]
If true, the carousel will show the previous/next buttons when hovering over the carousel.
- alwaysShowPagerButtons
bool
[false]
If true, the carousel will always show the previous/next buttons.
- showPaginator
bool
[false]
If true, the carousel will show the pagination dots.
- activePaginatorClassName
string
The
isActive
class that gets applied to the active paginator dot. - showControlArrows
bool
[false]
If true, the carousel will show left/right navigation arrows next to the pagination dots.
showPaginator
prop must also betrue
. - slidesPerPage
oneOf(1, 2, 3, 4, 5, 6)
[1]
- springFactor
number
[1]
The relative springiness of the slide animations. Higher values result in a more forceful animation. Should typically be between 0.5 and 1.5.
- animationDuration
number
[300]
Duration of slide animations, in milliseconds
- variableWidth
bool
[false]
Flag indicating that carousel has variable width slides. If this is true, the
slidesPerPage
andshowPaginator
props are ignored and grid items must define their own sizing. - snapPagersToImages
bool
[false]
Flag indicating that the carousel has images meant to align the pagers. Snaps the pager buttons to the first image in the carousel. Works best if all the images are the same size.