Airframe GitHub Storybook
Component

ba-media-viewer

A gallery component for viewing a range of images at full size

Airframe

Active
Figma

Web Components

Active
Storybook GitHub

React

Planned

React Native

Planned
Design Code Accessibility QA
A

Gallery heading

A general title for the gallery

B

Gallery control

Allows moving through the gallery

C

Image

The currently visible image

D

Image content

Content to help give context to the image. A title, description and tag can be used

E

Close button

Clicking this button will take the user back to the supplied href

F

Gallery item count

This shows the total amount of images in the gallery, and what image is currently visible

G

Progress meter

Shows the overall progress through the gallery

The media viewer component should be contained on its own page, allowing the images to take centre stage.

<ba-media-viewer gallery-heading="Gallery heading">
  <ba-media-viewer-slide
    image-title="Image title"
    alt="Description of image"
    aspect-ratio="1-1"
    src="demo-images/1-1.webp"
  >
    <ba-tag slot="tag"> Test Tag </ba-tag>
    <ba-content>
      <p>
        A short description about what the image is showing and any other
        details relating to British Airways route.
      </p>
    </ba-content>
  </ba-media-viewer-slide>
  <ba-media-viewer-slide
    image-title="Image title"
    alt="Description of image"
    src="demo-images/16-9.webp"
    aspect-ratio="16-9"
  >
    <ba-tag slot="tag"> Test Tag </ba-tag>
    <ba-content>
      <p>
        A short description about what the image is showing and any other
        details relating to British Airways route.
      </p>
    </ba-content>
  </ba-media-viewer-slide>
  <ba-media-viewer-slide
    image-title="Image title"
    alt="Description of image"
    src="demo-images/3-4.webp"
    aspect-ratio="3-4"
  >
    <ba-tag slot="tag"> Test Tag </ba-tag>
    <ba-content>
      <p>
        A short description about what the image is showing and any other
        details relating to British Airways route.
      </p>
    </ba-content>
  </ba-media-viewer-slide>
  <ba-media-viewer-slide
    image-title="Image title"
    aspect-ratio="1-1"
    alt="Description of image"
    src="demo-images/1-1.webp"
  >
    <ba-tag slot="tag"> Test Tag </ba-tag>
    <ba-content>
      <p>
        A short description about what the image is showing and any other
        details relating to British Airways route.
      </p>
    </ba-content>
  </ba-media-viewer-slide>
</ba-media-viewer>
Property Attribute Description Type Default
currentSlide(required) current-slide The index of the currently active slide. number undefined
galleryHeading(required) gallery-heading The heading for the gallery. string undefined
returnHref(required) return-href The URL to navigate to when the close button is clicked. string undefined
  • None
Slot Description Permitted elements
Unnamed slot Elements will render in the body of the component <ba‑media‑viewer‑slide>

None

Event Description Type
onBaSlideChange Fires whenever a slide in the viewer changes CustomEvent<any>

Basic usage using the <ba-media-viewer-slide> component which can take the following props.

Property Attribute Description Type Default
alt(required) alt The 'alt' attribute defines the alternative text for our image.
This will be used to help our visually impaired users using screen readers.
Also the text can be displayed when an image fails to load
string undefined
aspectRatio aspect-ratio Defines a set aspect ratio for our image, sets a proportional relationship
between the image's width and height.
"1-1" | "16-9" | "3-4" | "4-3" | "9-16" | "credit-card" | undefined '1-1'
imageTitle(required) image-title The title of the image string undefined
sizes sizes This defines the image size values string | undefined undefined
src(required) src The image URL. string undefined
srcSet srcset This defines the image srcset values string | undefined undefined
Basic usage with the <ba-media-viewer-slide> component
<ba-media-viewer gallery-heading="Gallery heading">
<ba-media-viewer-slide
image-title="Image title"
alt="Description of image"
aspect-ratio="1-1"
src="demo-images/1-1.webp"

>

    <ba-tag slot="tag"> Test Tag </ba-tag>
    <ba-content>
      <p>
        A short description about what the image is showing and any other
        details relating to British Airways route.
      </p>
    </ba-content>

  </ba-media-viewer-slide>
  <ba-media-viewer-slide
    image-title="Image title"
    alt="Description of image"
    src="demo-images/16-9.webp"
    aspect-ratio="16-9"
  >
    <ba-tag slot="tag"> Test Tag </ba-tag>
    <ba-content>
      <p>
        A short description about what the image is showing and any other
        details relating to British Airways route.
      </p>
    </ba-content>
  </ba-media-viewer-slide>
  <ba-media-viewer-slide
    image-title="Image title"
    alt="Description of image"
    src="demo-images/3-4.webp"
    aspect-ratio="3-4"
  >
    <ba-tag slot="tag"> Test Tag </ba-tag>
    <ba-content>
      <p>
        A short description about what the image is showing and any other
        details relating to British Airways route.
      </p>
    </ba-content>
  </ba-media-viewer-slide>
  <ba-media-viewer-slide
    image-title="Image title"
    aspect-ratio="1-1"
    alt="Description of image"
    src="demo-images/1-1.webp"
  >
    <ba-tag slot="tag"> Test Tag </ba-tag>
    <ba-content>
      <p>
        A short description about what the image is showing and any other
        details relating to British Airways route.
      </p>
    </ba-content>
  </ba-media-viewer-slide>
</ba-media-viewer>

You can update the gallery title depending on the shown slide by listening for the onBaSlideChange event

Updating the gallery title
<ba-media-viewer gallery-heading="Gallery heading">
<ba-media-viewer-slide
image-title="Image title"
alt="Description of image"
aspect-ratio="1-1"
src="demo-images/1-1.webp"

>

    <ba-tag slot="tag"> Test Tag </ba-tag>
    <ba-content>
      <p>
        A short description about what the image is showing and any other
        details relating to British Airways route.
      </p>
    </ba-content>

  </ba-media-viewer-slide>
  <ba-media-viewer-slide
    image-title="Image title"
    alt="Description of image"
    src="demo-images/16-9.webp"
    aspect-ratio="16-9"
  >
    <ba-tag slot="tag"> Test Tag </ba-tag>
    <ba-content>
      <p>
        A short description about what the image is showing and any other
        details relating to British Airways route.
      </p>
    </ba-content>
  </ba-media-viewer-slide>
</ba-media-viewer>

<script>
  const mediaViewer = document.querySelector('ba-media-viewer')

  if (!mediaViewer) {
    return
  }

  document.addEventListener('onBaSlideChange', (event) => {
    const newSlide = event.detail

    // Some condition to check the newSlide against

    mediaViewer.setAttribute('gallery-heading', 'New gallery title')
  })
</script>

srcset lets the browser pick the most efficient file for the current viewport and pixel density, while sizes tells it how wide the image will actually render.

Always provide a fallback src for browsers that don't understand srcset.

The media viewer caps the image height at 580px once the viewport reaches 1024px wide, so above that breakpoint the image stops growing with the viewport — it only needs higher pixel-density versions, not extra width.

Recommended settings for under 1024px wide (16:9 aspect ratio):

  • 320×180 320w
  • 480×270 480w
  • 640×360 640w
  • 960×540 960w
  • 1024×576 1024w

Use with sizes value of (min-width: 64rem) 1024px, 100vw and set the src value to the 320×180 image

Recommended settings for 1024px wide and over (16:9 aspect ratio, capped at a 580px max height):

  • 1024×576 1024w
  • 1536×864 1536w
  • 2048×1152 2048w

These give 1x, 1.5x and 2x pixel-density versions of the 1024×576 image that fills the 580px height cap — wider variants aren't needed because the image can never render taller than that.

The recommended sizes for the other aspect ratios are as follows:

1-1 (square, ratio 1):
  • 580×580 580w
  • 870×870 870w
  • 1160×1160 1160w
9-16 (portrait, ratio 9/16 ≈ 0.5625):
  • 326×580 326w
  • 489×870 489w
  • 652×1160 652w
4-3 (ratio 4/3 ≈ 1.333):
  • 773×580 773w
  • 1160×870 1160w
  • 1546×1160 1546w
3-4 (ratio 3/4 ≈ 0.75):
  • 435×580 435w
  • 653×870 653w
  • 870×1160 870w
credit-card (ratio ≈ 1.586):
  • 920×580 920w
  • 1380×870 1380w
  • 1840×1160 1840w
A media viewer slide using the recommended srcset and sizes values
<ba-media-viewer-slide
image-title="Image title"
alt="Description of image"
aspect-ratio="16-9"
src="16-9-image-320x180.webp"
srcset="16-9-image-320x180.webp 320w,
16-9-image-480x270.webp 480w,
16-9-image-640x360.webp 640w,
16-9-image-960x540.webp 960w,
16-9-image-1024x576.webp 1024w,
16-9-image-1536x864.webp 1536w,
16-9-image-2048x1152.webp 2048w"
sizes="(min-width: 64rem) 1024px, 100vw"

> <ba-tag slot="tag"> Test Tag </ba-tag>
> <ba-content>

    <p>A short description about what the image is showing and any other details relating to British Airways route.</p>

  </ba-content>
</ba-media-viewer-slide>

React documentation coming soon.

React Native documentation coming soon.

Due to the carousel items being accessible via the keyboard, the controls to move forward and backward in the carousel have been removed from the tab flow. This makes the behaviour less confusing for screen reader users as it stops duplication.

This enables screen reader users to know how many items are in the carousel, and gives a running count of which item they are on when moving through the carousel.

State: Previous element in the DOM has focus

⇥ Tab

Focus moves to the media-viewer close button

State: media-viewer close button has focus

⇥ Tab

Focus moves to the carousel container

State: Carousel container has focus

⇥ Tab

Focus moves to the first focusable element within the carousel, or the next focusable element in the DOM if no focusable elements are present

← Arrow Left

The carousel moves to the previous item

→ Arrow Right

The carousel moves to the next item

State: Focusable element within carousel item has focus

⇥ Tab

Focus moves to the next focusable element within the carousel items in sequential order, or to the next focusable element in the DOM if there are no more focusable elements within the carousel items

← Arrow Left

The carousel moves to the previous item, focus remains on the same focusable element

→ Arrow Right

The carousel moves to the next item, focus remains on the same focusable element

Use this checklist to confirm the component has been configured and used correctly.

  • Media within each slotted slide loads and displays correctly
  • return-href points to a valid, sensible destination within the app's routing
  • gallery-heading text provided is meaningful/descriptive for screen reader users

These checks are handled by the component and do not need to be repeated each time it is used.

  • Close button renders with the correct return-href attribute
  • Item count updates correctly when slides are added dynamically or the carousel emits a slideChange event
  • All hardcoded text has translations for every supported language
  • When the gallery gets updated it should announce it to screen readers
Designing Developing Components BAgel helper Web QA React Native QA britishairways.com Careers Cookie policy