<content-carousel class="carousel carousel--two-up" data-counter role="region" aria-roledescription="Karussell" aria-label="Success Stories">
    <div class="carousel__track" data-carousel-track>
        <a href="#" class="case-tile-teaser bg-image-edition-12">
            <div class="case-tile-teaser__content">
                <div class="case-tile-teaser__body">
                    <span class="case-tile-teaser__caption">Versicherung</span>
                    <h3 class="case-tile-teaser__headline">Einheitliche Security- und Compliance-Prozesse</h3>
                </div>
                <div class="case-tile-teaser__goto">
                    <span class="link-teaser">Zur Success Story</span>
                </div>
            </div>
        </a>
        <a href="#" class="case-tile-teaser bg-image-edition-07">
            <div class="case-tile-teaser__content">
                <div class="case-tile-teaser__body">
                    <span class="case-tile-teaser__caption">Immobilien</span>
                    <h3 class="case-tile-teaser__headline">Antworten statt Suchergebnisse mit generativer KI</h3>
                </div>
                <div class="case-tile-teaser__goto">
                    <span class="link-teaser">Zur Success Story</span>
                </div>
            </div>
        </a>
        <a href="#" class="case-tile-teaser bg-image-edition-27">
            <div class="case-tile-teaser__content">
                <div class="case-tile-teaser__body">
                    <span class="case-tile-teaser__caption">Bildung</span>
                    <h3 class="case-tile-teaser__headline">Aufbau einer Lernplattform</h3>
                </div>
                <div class="case-tile-teaser__goto">
                    <span class="link-teaser">Zur Success Story</span>
                </div>
            </div>
        </a>
        <a href="#" class="case-tile-teaser bg-image-edition-01">
            <div class="case-tile-teaser__content">
                <div class="case-tile-teaser__body">
                    <span class="case-tile-teaser__caption">Datenmanagement</span>
                    <h3 class="case-tile-teaser__headline">Data Governance ohne Handbremse</h3>
                </div>
                <div class="case-tile-teaser__goto">
                    <span class="link-teaser">Zur Success Story</span>
                </div>
            </div>
        </a>
        <a href="#" class="case-tile-teaser bg-image-edition-12">
            <div class="case-tile-teaser__content">
                <div class="case-tile-teaser__body">
                    <span class="case-tile-teaser__caption">Öffentliche Verwaltung</span>
                    <h3 class="case-tile-teaser__headline">UX als Treiber für Software-Modernisierung</h3>
                </div>
                <div class="case-tile-teaser__goto">
                    <span class="link-teaser">Zur Success Story</span>
                </div>
            </div>
        </a>
        <a href="#" class="case-tile-teaser bg-image-edition-07">
            <div class="case-tile-teaser__content">
                <div class="case-tile-teaser__body">
                    <span class="case-tile-teaser__caption">E-Commerce</span>
                    <h3 class="case-tile-teaser__headline">Eine moderne Architektur für zuverlässige Blumengrüße</h3>
                </div>
                <div class="case-tile-teaser__goto">
                    <span class="link-teaser">Zur Success Story</span>
                </div>
            </div>
        </a>
    </div>
</content-carousel>
<content-carousel class="carousel carousel--two-up" data-counter role="region" aria-roledescription="Karussell" aria-label="Success Stories">
    <div class="carousel__track" data-carousel-track>
        {{#each slides}}
        <a href="#" class="case-tile-teaser {{this.background}}">
            <div class="case-tile-teaser__content">
                <div class="case-tile-teaser__body">
                    <span class="case-tile-teaser__caption">{{this.caption}}</span>
                    <h3 class="case-tile-teaser__headline">{{this.headline}}</h3>
                </div>
                <div class="case-tile-teaser__goto">
                    <span class="link-teaser">Zur Success Story</span>
                </div>
            </div>
        </a>
        {{/each}}
    </div>
</content-carousel>
{
  "slides": [
    {
      "caption": "Versicherung",
      "headline": "Einheitliche Security- und Compliance-Prozesse",
      "background": "bg-image-edition-12"
    },
    {
      "caption": "Immobilien",
      "headline": "Antworten statt Suchergebnisse mit generativer KI",
      "background": "bg-image-edition-07"
    },
    {
      "caption": "Bildung",
      "headline": "Aufbau einer Lernplattform",
      "background": "bg-image-edition-27"
    },
    {
      "caption": "Datenmanagement",
      "headline": "Data Governance ohne Handbremse",
      "background": "bg-image-edition-01"
    },
    {
      "caption": "Öffentliche Verwaltung",
      "headline": "UX als Treiber für Software-Modernisierung",
      "background": "bg-image-edition-12"
    },
    {
      "caption": "E-Commerce",
      "headline": "Eine moderne Architektur für zuverlässige Blumengrüße",
      "background": "bg-image-edition-07"
    }
  ]
}
  • Content:
    $carousel-gap: $spacer-md;
    $carousel-control-size: 2rem;
    $carousel-control-size-large: 2.5rem;
    $carousel-icon-size: 0.7rem;
    $carousel-icon-size-large: 0.85rem;
    $carousel-counter-min-width: 3rem;
    $carousel-control-color: $brand-gray-50;
    $carousel-control-active-color: $brand-secondary;
    $carousel-transition: color 0.3s ease;
    
    @mixin carousel-base {
      display: flex;
      flex-direction: column;
      width: 100%;
    
      // The track clips overflow, so it leaves room for the hover glow of tiles.
      [data-carousel-track] {
        scroll-behavior: smooth;
        scroll-snap-type: x mandatory;
        scroll-padding-inline: $box-shadow-glow-size;
        overscroll-behavior-x: contain;
        overflow-x: auto;
        display: flex;
        gap: $carousel-gap;
        margin: (-$box-shadow-glow-size);
        padding: $box-shadow-glow-size;
    
        @media (prefers-reduced-motion: reduce) {
          scroll-behavior: auto;
        }
    
        > * {
          scroll-snap-align: start;
          flex: 0 0 100%;
          min-width: 0;
        }
      }
    
      &.carousel--enhanced [data-carousel-track] {
        scrollbar-width: none;
    
        &::-webkit-scrollbar {
          display: none;
        }
      }
    
      .carousel__controls {
        display: flex;
        order: 1;
        gap: $spacer-xs;
        align-items: center;
        justify-content: center;
        margin-top: $spacer-md;
    
        &[hidden] {
          display: none;
        }
      }
    }
    
    @mixin carousel-side-controls {
      &.carousel--enhanced:not(.carousel--static) {
        display: grid;
        grid-template-areas:
          'track track'
          'prev next';
        grid-template-columns: 1fr 1fr;
        gap: $spacer-md $spacer-xs;
    
        .carousel__controls {
          display: contents;
        }
    
        [data-carousel-track] {
          grid-area: track;
        }
    
        .carousel__btn--prev {
          grid-area: prev;
          justify-self: end;
        }
    
        .carousel__btn--next {
          grid-area: next;
          justify-self: start;
        }
    
        @media screen and (min-width: $grid-breakpoint-md) {
          grid-template-areas: 'prev track next';
          grid-template-columns: auto minmax(0, 1fr) auto;
          column-gap: $spacer-base;
          align-items: center;
    
          .carousel__btn--prev,
          .carousel__btn--next {
            justify-self: center;
          }
        }
      }
    
      [data-carousel-track] {
        align-items: flex-start;
      }
    
      .carousel__btn {
        width: $carousel-control-size-large;
        height: $carousel-control-size-large;
      }
    
      .carousel__icon {
        width: $carousel-icon-size-large;
        height: $carousel-icon-size-large;
      }
    }
    
    .carousel {
      @include carousel-base;
    }
    
    .carousel--two-up [data-carousel-track] > * {
      @media screen and (min-width: $grid-breakpoint-md) {
        flex-basis: calc((100% - #{$carousel-gap}) / 2);
    
        &:nth-child(2n) {
          scroll-snap-align: none;
        }
      }
    }
    
    .carousel--side-controls {
      @include carousel-side-controls;
    }
    
    .carousel__btn {
      cursor: pointer;
    
      display: inline-flex;
      flex-shrink: 0;
      align-items: center;
      justify-content: center;
    
      width: $carousel-control-size;
      height: $carousel-control-size;
      padding: 0;
    
      color: $carousel-control-color;
    
      appearance: none;
      background: none;
      border: 1px solid currentcolor;
      border-radius: 50%;
    
      transition: $carousel-transition;
    
      &:hover:not(:disabled),
      &:focus-visible {
        color: $carousel-control-active-color;
      }
    
      &:disabled {
        cursor: default;
        opacity: 0.4;
      }
    
      @media (forced-colors: active) {
        border-color: ButtonText;
      }
    }
    
    .carousel__icon {
      display: block;
      width: $carousel-icon-size;
      height: $carousel-icon-size;
      background-color: currentcolor;
    
      @media (forced-colors: active) {
        background-color: ButtonText;
      }
    }
    
    .carousel__icon--prev {
      clip-path: polygon(70% 0, 85% 15%, 50% 50%, 85% 85%, 70% 100%, 20% 50%);
    }
    
    .carousel__icon--next {
      clip-path: polygon(30% 0, 15% 15%, 50% 50%, 15% 85%, 30% 100%, 80% 50%);
    }
    
    .carousel__counter {
      @extend %heading-font-regular;
    
      min-width: $carousel-counter-min-width;
      font-size: $font-size-xs;
      color: $brand-gray-75;
      text-align: center;
    }
    
    // Progress segments: one per page, clickable, the current one fills while autoplay runs.
    $carousel-segment-width: 2.2rem;
    $carousel-segment-gap: 0.6rem;
    $carousel-segment-height: 2px;
    $carousel-segment-active-height: 4px;
    $carousel-segment-hit-height: 1.5rem;
    $carousel-segment-color: $brand-gray-75;
    $carousel-segment-hover-color: $brand-apricot;
    $carousel-segment-active-color: $brand-petrol;
    $carousel-segment-track-color: $brand-petrol-25;
    $carousel-toggle-size: 1.7rem;
    $carousel-toggle-icon-size: 0.6rem;
    
    .carousel__controls--progress {
      flex-direction: column;
      gap: $spacer-xxs;
    }
    
    .carousel__progress {
      display: flex;
      gap: $carousel-segment-gap;
      justify-content: center;
    }
    
    .carousel__segment {
      cursor: pointer;
    
      display: flex;
      align-items: center;
    
      width: $carousel-segment-width;
      height: $carousel-segment-hit-height;
      padding: 0;
    
      appearance: none;
      background: none;
      border: 0;
    
      &:focus-visible {
        outline: 2px solid $carousel-control-active-color;
        outline-offset: 2px;
      }
    }
    
    .carousel__segment-fill {
      position: relative;
    
      overflow: hidden;
      display: block;
    
      width: 100%;
      height: $carousel-segment-height;
    
      background-color: $carousel-segment-color;
    
      &::after {
        content: '';
    
        position: absolute;
        inset: 0;
        transform: scaleX(0);
        transform-origin: left;
    
        background-color: $carousel-segment-active-color;
      }
    
      .carousel__segment:not([aria-current]):hover & {
        background-color: $carousel-segment-hover-color;
      }
    
      [aria-current='true'] > & {
        height: $carousel-segment-active-height;
    
        background-color: $carousel-segment-track-color;
      }
    
      [aria-current='true'] > &::after {
        transform: scaleX(1);
      }
    
      @media (prefers-reduced-motion: no-preference) {
        [data-autoplay]:not([data-paused]) [aria-current='true'] > &::after {
          transform: scaleX(0);
          animation: carousel-segment-fill var(--carousel-autoplay-duration, 8s) linear forwards;
          animation-play-state: paused;
        }
    
        [data-autoplay][data-running] [aria-current='true'] > &::after {
          animation-play-state: running;
        }
      }
    
      @media (forced-colors: active) {
        background-color: GrayText;
    
        &::after {
          background-color: Highlight;
        }
      }
    }
    
    .carousel__toggle {
      order: 1;
      width: $carousel-toggle-size;
      height: $carousel-toggle-size;
      border-color: $carousel-segment-color;
    
      &:hover,
      &:focus-visible {
        border-color: $carousel-control-active-color;
      }
    
      .carousel__icon {
        width: $carousel-toggle-icon-size;
        height: $carousel-toggle-icon-size;
      }
    }
    
    .carousel__icon--toggle {
      clip-path: polygon(10% 0, 40% 0, 40% 100%, 10% 100%, 10% 0, 60% 0, 90% 0, 90% 100%, 60% 100%, 60% 0);
    
      [data-paused] & {
        clip-path: polygon(20% 0, 95% 50%, 20% 100%);
      }
    }
    
    @keyframes carousel-segment-fill {
      from {
        transform: scaleX(0);
      }
    
      to {
        transform: scaleX(1);
      }
    }
    
  • URL: /components/raw/carousel/_carousel.scss
  • Filesystem Path: components/04-molecules/carousel/_carousel.scss
  • Size: 6.8 KB
  • Content:
    const REDUCED_MOTION = '(prefers-reduced-motion: reduce)'
    const SCROLL_TOLERANCE = 2
    const DEFAULT_AUTOPLAY_DELAY = 8000
    const MIN_AUTOPLAY_DELAY = 2000
    
    const DEFAULT_LABELS = {
      previous: 'Zurück',
      next: 'Weiter',
      slide: 'Folie',
      position: '{current} von {total}',
      pause: 'Automatischen Durchlauf anhalten',
      play: 'Automatischen Durchlauf starten',
      progress: 'Folie wählen',
    }
    
    export default class Carousel extends HTMLElement {
      connectedCallback() {
        this.track = this.querySelector('[data-carousel-track]')
        if (!this.track) return
    
        this.slides = [...this.track.children]
        if (this.slides.length < 2) return
    
        this.motionQuery = window.matchMedia(REDUCED_MOTION)
        // A cloned element (e.g. a page snapshot) may bring along the controls of the original.
        this.querySelectorAll(':scope > .carousel__controls, :scope > .carousel__status').forEach((element) =>
          element.remove(),
        )
        this.removeAttribute('data-running')
        this.removeAttribute('data-paused')
        this.describeSlides()
        this.createControls()
    
        this.handleScroll = () => this.scheduleUpdate()
        this.track.addEventListener('scroll', this.handleScroll, { passive: true })
        this.resizeObserver = new ResizeObserver(() => this.scheduleUpdate())
        this.resizeObserver.observe(this.track)
    
        this.update()
        if (this.toggleButton) this.startAutoplay()
      }
    
      disconnectedCallback() {
        this.track?.removeEventListener('scroll', this.handleScroll)
        this.resizeObserver?.disconnect()
        this.resizeObserver = null
        this.stopAutoplay()
        cancelAnimationFrame(this.frame)
        this.controls?.remove()
        this.status?.remove()
        this.controls = null
        this.status = null
        this.prevButton = null
        this.nextButton = null
        this.counter = null
        this.progress = null
        this.toggleButton = null
        this.currentIndex = undefined
        this.classList.remove('carousel--enhanced', 'carousel--static')
        this.style.removeProperty('--carousel-autoplay-duration')
        this.removeAttribute('data-running')
        this.removeAttribute('data-paused')
      }
    
      label(key) {
        const attribute = `label${key[0].toUpperCase()}${key.slice(1)}`
        return this.dataset[attribute] || DEFAULT_LABELS[key]
      }
    
      fillIn(template, current, total) {
        return template.replace('{current}', current).replace('{total}', total)
      }
    
      describeSlides() {
        this.slides.forEach((slide, index) => {
          if (!slide.hasAttribute('role')) slide.setAttribute('role', 'group')
          if (!slide.hasAttribute('aria-roledescription')) {
            slide.setAttribute('aria-roledescription', this.label('slide'))
          }
          if (!slide.hasAttribute('aria-label')) {
            slide.setAttribute('aria-label', this.fillIn(this.label('position'), index + 1, this.slides.length))
          }
        })
      }
    
      createControls() {
        this.controls = document.createElement('div')
        this.controls.className = 'carousel__controls'
    
        // Clickable progress segments replace the arrows and the counter.
        if (this.hasAttribute('data-progress')) {
          this.progress = document.createElement('div')
          this.progress.className = 'carousel__progress'
          this.progress.setAttribute('role', 'group')
          this.progress.setAttribute('aria-label', this.label('progress'))
          this.controls.classList.add('carousel__controls--progress')
          this.controls.append(this.progress)
        } else {
          this.prevButton = this.createButton('prev', this.label('previous'))
          this.prevButton.addEventListener('click', () => this.interact(() => this.step(-1)))
    
          this.nextButton = this.createButton('next', this.label('next'))
          this.nextButton.addEventListener('click', () => this.interact(() => this.step(1)))
    
          this.controls.append(this.prevButton)
          if (this.hasAttribute('data-counter')) {
            this.counter = document.createElement('span')
            this.counter.className = 'carousel__counter'
            this.counter.setAttribute('aria-hidden', 'true')
            this.controls.append(this.counter)
          }
          this.controls.append(this.nextButton)
        }
    
        // First in the DOM so keyboard users reach it before the slides (WAI carousel pattern).
        if (this.hasAttribute('data-autoplay')) {
          this.toggleButton = this.createButton('toggle', this.label('pause'))
          this.toggleButton.classList.add('carousel__toggle')
          this.toggleButton.addEventListener('click', () => this.setPaused(!this.paused))
          this.controls.prepend(this.toggleButton)
        }
    
        this.status = document.createElement('p')
        this.status.className = 'carousel__status sr-only'
        this.status.setAttribute('aria-live', 'polite')
    
        this.track.before(this.controls)
        this.append(this.status)
        this.classList.add('carousel--enhanced')
      }
    
      createButton(direction, label) {
        const button = document.createElement('button')
        button.type = 'button'
        button.className = `carousel__btn carousel__btn--${direction}`
        button.setAttribute('aria-label', label)
        button.innerHTML = `<span class="carousel__icon carousel__icon--${direction}" aria-hidden="true"></span>`
        return button
      }
    
      // Page starts are the slides that act as snap points; CSS decides which.
      pageStarts() {
        const origin = this.slides[0].offsetLeft
        const maxScroll = this.track.scrollWidth - this.track.clientWidth
        const starts = this.slides
          .filter((slide) => getComputedStyle(slide).scrollSnapAlign !== 'none')
          .map((slide) => Math.min(slide.offsetLeft - origin, maxScroll))
        return [...new Set(starts)]
      }
    
      currentPage(starts) {
        const position = this.track.scrollLeft
        let closest = 0
        starts.forEach((start, index) => {
          if (Math.abs(start - position) < Math.abs(starts[closest] - position)) {
            closest = index
          }
        })
        return closest
      }
    
      step(direction) {
        const starts = this.pageStarts()
        this.goTo(this.currentPage(starts) + direction, starts)
      }
    
      goTo(page, starts = this.pageStarts(), announce = true) {
        const target = Math.max(0, Math.min(page, starts.length - 1))
        this.track.scrollTo({
          left: starts[target],
          behavior: this.motionQuery.matches ? 'auto' : 'smooth',
        })
        if (announce) this.status.textContent = this.fillIn(this.label('position'), target + 1, starts.length)
      }
    
      // Manual navigation stops the automatic rotation until play is pressed.
      interact(action) {
        if (this.toggleButton && !this.paused) this.setPaused(true)
        action()
      }
    
      startAutoplay() {
        const delay = Number.parseInt(this.dataset.autoplay, 10)
        this.delay = delay >= MIN_AUTOPLAY_DELAY ? delay : DEFAULT_AUTOPLAY_DELAY
        this.style.setProperty('--carousel-autoplay-duration', `${this.delay}ms`)
        this.remaining = this.delay
        this.running = false
        this.hovered = false
        this.focused = false
        this.touching = false
        this.swiped = false
        this.visible = false
    
        const set = (key, value) => () => {
          this[key] = value
          this.syncAutoplay()
        }
        this.handlePointerEnter = set('hovered', true)
        this.handlePointerLeave = set('hovered', false)
        // Focus anywhere but on the toggle holds the rotation, so pressing play still starts it.
        this.handleFocusIn = (event) => {
          this.focused = event.target !== this.toggleButton
          this.syncAutoplay()
        }
        this.handleFocusOut = (event) => {
          const next = event.relatedTarget
          this.focused = Boolean(next) && this.contains(next) && next !== this.toggleButton
          this.syncAutoplay()
        }
        this.handleTouchStart = () => {
          this.touching = true
          this.swiped = true
          this.syncAutoplay()
        }
        this.handleTouchEnd = set('touching', false)
        // Only horizontal wheel movement scrolls the track; vertical page scrolling is ignored.
        this.handleWheel = (event) => {
          if (Math.abs(event.deltaX) > Math.abs(event.deltaY)) this.interact(() => {})
        }
        this.handleVisibility = () => this.syncAutoplay()
    
        this.track.addEventListener('pointerenter', this.handlePointerEnter)
        this.track.addEventListener('pointerleave', this.handlePointerLeave)
        this.addEventListener('focusin', this.handleFocusIn)
        this.addEventListener('focusout', this.handleFocusOut)
        this.track.addEventListener('touchstart', this.handleTouchStart, { passive: true })
        this.track.addEventListener('touchend', this.handleTouchEnd)
        this.track.addEventListener('touchcancel', this.handleTouchEnd)
        this.track.addEventListener('wheel', this.handleWheel, { passive: true })
        document.addEventListener('visibilitychange', this.handleVisibility)
    
        this.intersectionObserver = new IntersectionObserver(
          ([entry]) => {
            this.visible = entry.isIntersecting
            this.syncAutoplay()
          },
          { threshold: 0.5 },
        )
        this.intersectionObserver.observe(this)
    
        this.setPaused(this.motionQuery.matches)
      }
    
      stopAutoplay() {
        clearTimeout(this.timer)
        this.timer = null
        this.running = false
        this.intersectionObserver?.disconnect()
        this.intersectionObserver = null
        if (!this.handlePointerEnter) return
        this.track.removeEventListener('pointerenter', this.handlePointerEnter)
        this.track.removeEventListener('pointerleave', this.handlePointerLeave)
        this.removeEventListener('focusin', this.handleFocusIn)
        this.removeEventListener('focusout', this.handleFocusOut)
        this.track.removeEventListener('touchstart', this.handleTouchStart)
        this.track.removeEventListener('touchend', this.handleTouchEnd)
        this.track.removeEventListener('touchcancel', this.handleTouchEnd)
        this.track.removeEventListener('wheel', this.handleWheel)
        document.removeEventListener('visibilitychange', this.handleVisibility)
        this.handlePointerEnter = null
      }
    
      setPaused(paused) {
        this.paused = paused
        this.toggleAttribute('data-paused', paused)
        this.toggleButton.setAttribute('aria-label', this.label(paused ? 'play' : 'pause'))
        if (paused) this.remaining = this.delay
        this.syncAutoplay()
      }
    
      // A pausable timer; the progress fill animation runs only while [data-running] is set.
      syncAutoplay() {
        const held = this.hovered || this.focused || this.touching
        const running =
          !this.paused && !held && this.visible && !document.hidden && !this.classList.contains('carousel--static')
        if (running === this.running) return
    
        this.running = running
        this.toggleAttribute('data-running', running)
        if (running) {
          this.armTimer()
        } else {
          clearTimeout(this.timer)
          this.remaining = Math.max(0, this.remaining - (performance.now() - this.timerStart))
        }
      }
    
      armTimer() {
        clearTimeout(this.timer)
        this.timerStart = performance.now()
        this.timer = setTimeout(() => this.advance(), this.remaining)
      }
    
      advance() {
        this.swiped = false
        const starts = this.pageStarts()
        const current = this.currentPage(starts)
        this.goTo(current + 1 < starts.length ? current + 1 : 0, starts, false)
        // Re-arm in case the scroll does not change the page; a page change re-arms it anyway.
        this.restartAutoplay()
      }
    
      // Called when the visible page changes, however that happened.
      restartAutoplay() {
        if (!this.toggleButton) return
        this.remaining = this.delay
        if (this.running) this.armTimer()
      }
    
      renderProgress(count, current) {
        if (this.progress.children.length !== count) {
          const focusedIndex = [...this.progress.children].indexOf(document.activeElement)
          this.progress.replaceChildren(
            ...Array.from({ length: count }, (_, index) => {
              const segment = document.createElement('button')
              segment.type = 'button'
              segment.className = 'carousel__segment'
              const ownLabel = count === this.slides.length && this.slides[index].dataset.carouselLabel
              segment.setAttribute(
                'aria-label',
                ownLabel || `${this.label('slide')} ${this.fillIn(this.label('position'), index + 1, count)}`,
              )
              segment.innerHTML = '<span class="carousel__segment-fill"></span>'
              segment.addEventListener('click', () => this.interact(() => this.goTo(index)))
              return segment
            }),
          )
          if (focusedIndex >= 0) this.progress.children[Math.min(focusedIndex, count - 1)].focus()
          this.currentIndex = undefined
        }
        ;[...this.progress.children].forEach((segment, index) => {
          if (index === current) segment.setAttribute('aria-current', 'true')
          else segment.removeAttribute('aria-current')
        })
      }
    
      scheduleUpdate() {
        cancelAnimationFrame(this.frame)
        this.frame = requestAnimationFrame(() => this.update())
      }
    
      update() {
        const { scrollLeft, scrollWidth, clientWidth } = this.track
        const maxScroll = scrollWidth - clientWidth
        const scrollable = maxScroll > SCROLL_TOLERANCE
    
        this.controls.hidden = !scrollable
        this.classList.toggle('carousel--static', !scrollable)
        if (this.handlePointerEnter) this.syncAutoplay()
        if (!scrollable) return
    
        if (this.prevButton) {
          this.prevButton.disabled = scrollLeft <= SCROLL_TOLERANCE
          this.nextButton.disabled = scrollLeft >= maxScroll - SCROLL_TOLERANCE
        }
        if (!this.counter && !this.progress && !this.toggleButton) return
    
        const starts = this.pageStarts()
        const current = this.currentPage(starts)
        if (this.counter) this.counter.textContent = `${current + 1} / ${starts.length}`
        if (this.progress) this.renderProgress(starts.length, current)
        if (current !== this.currentIndex) {
          // A swipe that changes the page counts as manual navigation.
          if (this.swiped && this.currentIndex !== undefined && this.toggleButton && !this.paused) this.setPaused(true)
          this.currentIndex = current
          this.restartAutoplay()
        }
      }
    }
    
  • URL: /components/raw/carousel/carousel.js
  • Filesystem Path: components/04-molecules/carousel/carousel.js
  • Size: 13.8 KB
  • Content:
    import Carousel from './carousel.js'
    
    // Kept so existing imports of dist/js/components/quote-carousel keep working.
    export default class QuoteCarousel extends Carousel {}
    
  • URL: /components/raw/carousel/quote-carousel.js
  • Filesystem Path: components/04-molecules/carousel/quote-carousel.js
  • Size: 172 Bytes

Scroll-snap carousel with progressive enhancement. Without JavaScript the track is a horizontally scrollable list with a visible scrollbar.

The <content-carousel> element adds previous/next buttons above the track in the DOM (shown below it), an optional page counter (data-counter) and a polite live region. Buttons move one page at a time and are disabled at both ends. Controls are hidden when everything fits.

Options:

  • data-progress: one clickable line per page instead of the arrows. A slide can name its line with data-carousel-label.
  • data-autoplay (delay in ms, default 8000): slides on by itself and starts over after the last page; with data-progress the current line fills over that time. Adds a pause/play button, first in the tab order (WCAG 2.2.2). Hovering or focusing the slides holds it, clicking a line or arrow, swiping or scrolling stops it, and play restarts the timer on the current page. It never starts with prefers-reduced-motion and only runs while visible.
  • data-progress replaces arrows and counter (data-counter is ignored) and is not meant to be combined with carousel--side-controls.

Every child of [data-carousel-track] is a slide and gets role="group", aria-roledescription and a position label unless it already has them.

Modifiers:

  • carousel--two-up: two slides per page from the md breakpoint.
  • carousel--side-controls: arrows left and right of the track (below it on small screens), slides keep their own height and align to the top. The track is as tall as the tallest slide, so the page never jumps.

Labels (data-label-previous, data-label-next, data-label-slide, data-label-position with {current}/{total}, data-label-pause, data-label-play, data-label-progress) default to German.