# @salt-ds/embla-carousel

## 1.1.7

### Patch Changes

- 4f1b504: Fixed references to undeclared dependencies, which could fail to resolve under strict package managers such as Yarn PnP, or pnpm with hoisting disabled.

  - `@salt-ds/styles` now depends on `clsx`.
  - `@salt-ds/embla-carousel` now depends on `@salt-ds/styles` and `@salt-ds/window`, and takes Embla's types from `embla-carousel-react` instead of importing the undeclared `embla-carousel`, so `embla-carousel` no longer needs to be installed for its types.
  - `@salt-ds/core` types now only reference `@floating-ui/react`, instead of its transitive dependencies `@floating-ui/core`, `@floating-ui/dom`, `@floating-ui/react-dom` and `@floating-ui/utils`. `margin` takes its `Middleware` type from `@floating-ui/react`, `useTooltip` has an explicit return type, and `DEFAULT_FLOATING_UI_MIDDLEWARE` is typed as `Middleware[]`.

- 55f27de: `CarouselAutoplayIndicator` and the carousel's tabs now show their names in React DevTools instead of being anonymous.
- Updated dependencies [fd5ae98]
- Updated dependencies [4f1b504]
- Updated dependencies [75f2d7d]
- Updated dependencies [61228a7]
- Updated dependencies [f8925a2]
- Updated dependencies [825f63d]
- Updated dependencies [4aa4585]
- Updated dependencies [55f27de]
- Updated dependencies [602ddb5]
- Updated dependencies [fd1bf44]
- Updated dependencies [75f2d7d]
- Updated dependencies [7182ee8]
- Updated dependencies [7182ee8]
- Updated dependencies [825f63d]
- Updated dependencies [825f63d]
- Updated dependencies [825f63d]
- Updated dependencies [825f63d]
- Updated dependencies [cb2e335]
  - @salt-ds/core@1.73.0
  - @salt-ds/styles@0.4.2

## 1.1.6

### Patch Changes

- 0e83a66: Updated Embla Carousel styles to use the current border style token.
- Updated dependencies [6c12378]
- Updated dependencies [2892934]
- Updated dependencies [416d4b8]
  - @salt-ds/core@1.70.0

## 1.1.5

### Patch Changes

- 6c57a1f: Fixed the carousel jumping before drag starts when clicking or touching a partially visible slide in multi-slide mode.
- Updated dependencies [fc59869]
- Updated dependencies [e3c0230]
- Updated dependencies [e25daab]
- Updated dependencies [b573303]
- Updated dependencies [e25daab]
- Updated dependencies [df76f3e]
- Updated dependencies [9c4e307]
  - @salt-ds/core@1.69.0

## 1.1.4

### Patch Changes

- 588b358: Fixed several issues with `Carousel` when used in multi-slide mode:

  - The carousel no longer snaps back to the first slide when the number of slides is not evenly divisible by `slidesToScroll` (e.g. 5 slides with `slidesToScroll: 2`).
  - Arrow key navigation now moves focus one slide at a time, only scrolling the track when the next slide is in a different snap group.
  - `Tab` and `Shift+Tab` now move focus only between currently visible slides, preventing unintended scrolling when focusing the last slide group.

- Updated dependencies [9729a10]
- Updated dependencies [52daa64]
- Updated dependencies [ed2779c]
- Updated dependencies [07e4d5d]
  - @salt-ds/core@1.64.0

## 1.1.3

### Patch Changes

- 89429e2: Updated accent token usage, to align to the recent theme change.
- Updated dependencies [5c36edc]
- Updated dependencies [cfc1591]
- Updated dependencies [89429e2]
- Updated dependencies [0a08ae0]
- Updated dependencies [5c36edc]
  - @salt-ds/core@1.59.0

## 1.1.2

### Patch Changes

- a7932f1: Fix `emblaOptions.startIndex` not working on React 16 and 17.
- Updated dependencies [23b5f53]
- Updated dependencies [aae0846]
- Updated dependencies [133a519]
- Updated dependencies [503c186]
  - @salt-ds/core@1.58.0

## 1.1.1

### Patch Changes

- 0445a79: Fixed holding left or right arrow key not navigating to the first or last slide in the carousel when using the carousel slides.
- Updated dependencies [47d113d]
- Updated dependencies [a16cbc5]
  - @salt-ds/core@1.57.0

## 1.1.0

### Minor Changes

- 972e37e: Added mobile density tokens.

### Patch Changes

- Updated dependencies [972e37e]
- Updated dependencies [4507919]
  - @salt-ds/core@1.56.0

## 1.0.0

### Major Changes

- da42e9a: Carousel is now a stable API.

  Features include:

  - Composable Salt controls for navigation and progress.
  - Composable with custom content within slides.
  - Built on the popular `embla-carousel` library, with Salt-specific accessibility and theming enhancements.

  Refer to [example](https://saltdesignsystem.com/salt/components/carousel/usage#sequential-with-slide-group) for basic usage.

### Patch Changes

- Updated dependencies [61c2bad]
- Updated dependencies [fef411f]
  - @salt-ds/core@1.51.0

## 0.1.6

### Patch Changes

- 30fc785: Accessibility updates for Carousel

  - Carousel now passes WCAG 2.1 AA requirements, if implemented as per documentation.
  - Removed next/prev buttons from focus order, when displaying a tablist.
  - Slides and actions within slides are now focusable.

  Removed embla plugin `CarouselAnnouncementPlugin.ts` as it is no longer needed.

  ```diff
  - import { CarouselAnnouncementPlugin } from "./CarouselAnnouncementPlugin";
    <Carousel
      aria-label="Account overview"
      getEmblaApi={setEmblaApi}
   -  emblaPlugins={[CarouselAnnouncementPlugin()]}
    >
    </Carousel>
  ```

- Updated dependencies [378fc01]
- Updated dependencies [1f53f12]
- Updated dependencies [22fed0d]
- Updated dependencies [770bc9c]
- Updated dependencies [54e4b19]
- Updated dependencies [bbb7dba]
- Updated dependencies [c3df8d8]
  - @salt-ds/core@1.49.0

## 0.1.5

### Patch Changes

- Updated dependencies [f1dc9fc]
- Updated dependencies [f1dc9fc]
- Updated dependencies [9560539]
  - @salt-ds/core@1.48.0

## 0.1.4

### Patch Changes

- Updated dependencies [846d975]
- Updated dependencies [8538730]
- Updated dependencies [8261887]
- Updated dependencies [e6445dc]
- Updated dependencies [ff646e2]
- Updated dependencies [9a25824]
- Updated dependencies [64ef723]
  - @salt-ds/core@1.47.5

## 0.1.3

### Patch Changes

- Updated dependencies [c58279f]
- Updated dependencies [239d20c]
- Updated dependencies [fe8da62]
  - @salt-ds/core@1.47.4

## 0.1.2

### Patch Changes

- Updated dependencies [55e7bc5]
- Updated dependencies [3481308]
- Updated dependencies [851e4cb]
  - @salt-ds/core@1.47.3

## 0.1.1

### Patch Changes

- Updated dependencies [cdce628]
- Updated dependencies [454686b]
- Updated dependencies [f25a82b]
- Updated dependencies [6bc8e53]
  - @salt-ds/core@1.47.2

## 0.1.0

### Minor Changes

- 9c4575b: ### Summary

  The `Carousel` component has been moved from the Lab package to its own package, `@salt-ds/embla-carousel`.
  Initially released as a pre-release in Lab, the Carousel was not fully featured. We have now pivoted to treating Carousel as a pattern using Embla, that can compose Salt components as its slides.

  [Embla](https://www.embla-carousel.com) is a headless open-source carousel library offering a comprehensive set of features and an extensible API.

  ### Migration Guide

  To allow consumers to manage their own version of Embla, it's defined as a peer dependency.

  To migrate from the current Lab version of `Carousel`:

  1. Define `embla-carousel-react` in your package.json.

  ```diff
  "dependencies": {
  +  "embla-carousel-react": "^8.6.0",
  }
  ```

  2. Update your imports.

  ```diff
  import {
    Carousel,
  - CarouselControls,
  + CarouselNextButton,
  + CarouselPreviousButton,
  + CarouselProgressLabel,
  - CarouselSlide,
  + CarouselCard,
  - CarouselSlider,
  + CarouselSlides
  -} from "@salt-ds/lab";
  +} from "@salt-ds/embla-carousel";
  ```

  ### Key Changes

  - `CarouselControls` has been broken into `CarouselPreviousButton`, `CarouselNextButton`, and `CarouselProgressLabel` for composability.
  - `CarouselSlide` has been renamed to `CarouselCard`. While `CarouselCard` is a predefined slide, you can also create custom slides.
  - `CarouselSlider` has been renamed to `CarouselSlides`.

  Example Update:

  ```diff
    const slideId = useId();

  - <Carousel controlsPlacement="bottom">
  + <Carousel>
  -   <CarouselControls />
  +   <CarouselPreviousButton />
  +   <CarouselNextButton />
  +   <CarouselProgressLabel />
  -   <CarouselSlider>
  +   <CarouselSlides>
      {
        slides.map((slide, index) => (
  -         <CarouselSlide
  +         <CarouselCard
              key={`${slideId}-${index}`}
  +           id={`${slideId}-${index}`}
              appearance={appearance}
              header={<H3>{slide.title}</H3>}
              media={
              <img
                 className="carousel-image-placeholder"
                 alt="stock content to show carousel slide"
                 src={slide.image}
              />}
              actions={withActions && <Link href="#">{slide.link}</Link>}
           >
              <Text>{slide.content}</Text>
           </CarouselCard>
    ))
    }
  -   </CarouselSlider>
  +   </CarouselSlides>
  </Carousel>
  ```

  ### Additional Configuration/Control of Carousel

  The Carousel can be configured using the Embla API.

  To configure Embla, pass `emblaOptions` or `emblaPlugins` to the Carousel.

  To control the behavior of the Carousel through the Embla API, obtain a reference to the Embla API through the `getEmblaApi` prop.

  ```
  const [emblaApi, setEmblaApi] = useState<CarouselEmblaApiType | null>(null);

  const slideId = useId();
  const { matchedBreakpoints } = useBreakpoint();
  const isMobile = matchedBreakpoints.indexOf("sm") === -1;

  useEffect(() => {
    if (!emblaApi) {
      return;
    }

    const logSnappedSlide = () => {
      const snappedSlideIndex = emblaApi.selectedScrollSnap();
      console.log(
        `Slide ${snappedSlideIndex !== undefined ? snappedSlideIndex + 1 : undefined} is snapped into view.`,
      );
    };

    emblaApi.on("select", logSnappedSlide);

    // Cleanup listener on component unmount
    return () => {
      emblaApi.off("select", logSnappedSlide);
    };
  }, [emblaApi]);

  return (
    <Carousel
      aria-label="Account overview"
      getEmblaApi={setEmblaApi}
    >
      <CarouselSlides>
        {slides.map((index) => (
          <div
            aria-label={`Example slide ${index + 1}`}
            aria-roledescription="slide"
            key={`${slideId}-${slide.title.replace(/ /g, "-")}-${index}`}
            id={`${slideId}-${slide.title.replace(/ /g, "-")}-${index}`}
          >
              {index + 1}
          </div>
        ))}
      </CarouselSlides>
    </Carousel>
  );
  ```

  Due to the challenges of making an accessible carousel, please read the documentation to understand the responsibilities that come with usage.

  `Carousel` remains in a pre-release state for this release and subject to feedback will be promoted to stable in a forthcoming release.

  ### Additional components

  - `CarouselTabList`: A tablist for navigating between slides.
  - `CarouselTab`: A tab button used by `CarouselTabList`.
  - `CarouselAutoplayIndicator`: An animated countdown indicator for autoplay functionality.
  - `CarouselAnnouncementPlugin`: A plugin for announcing slide changes to assistive technologies.

### Patch Changes

- Updated dependencies [62975de]
- Updated dependencies [b96166e]
- Updated dependencies [73ccf6b]
- Updated dependencies [95dd874]
- Updated dependencies [c93c943]
- Updated dependencies [104d776]
- Updated dependencies [621253b]
  - @salt-ds/core@1.47.1
