ba-media-viewer
A gallery component for viewing a range of images at full size
Airframe
Web Components
React
React Native
Anatomy
Gallery heading
A general title for the gallery
Gallery control
Allows moving through the gallery
Image
The currently visible image
Image content
Content to help give context to the image. A title, description and tag can be used
Close button
Clicking this button will take the user back to the supplied href
Gallery item count
This shows the total amount of images in the gallery, and what image is currently visible
Progress meter
Shows the overall progress through the gallery
Design Documentation
The media viewer component should be contained on its own page, allowing the images to take centre stage.
Live Demo
A short description about what the image is showing and any other details relating to British Airways route.
A short description about what the image is showing and any other details relating to British Airways route.
A short description about what the image is showing and any other details relating to British Airways route.
A short description about what the image is showing and any other details relating to British Airways route.
<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>
Properties and attributes
| 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 |
Permitted ARIA roles
- None
Slots
| Slot | Description | Permitted elements |
|---|---|---|
| Unnamed slot | Elements will render in the body of the component | <ba‑media‑viewer‑slide> |
Parent components
None
Events
| Event | Description | Type |
|---|---|---|
onBaSlideChange |
Fires whenever a slide in the viewer changes | CustomEvent<any> |
Usage
Basic usage
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 |
<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>
Updating the gallery title
You can update the gallery title depending on the shown slide by listening for the onBaSlideChange event
<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>
Using srcset and sizes
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
<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>
Guidelines
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.
Keyboard navigation
State: Previous element in the DOM has focus
Focus moves to the media-viewer close button
State: media-viewer close button has focus
Focus moves to the carousel container
State: Carousel container has focus
Focus moves to the first focusable element within the carousel, or the next focusable element in the DOM if no focusable elements are present
The carousel moves to the previous item
The carousel moves to the next item
State: Focusable element within carousel item has focus
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
The carousel moves to the previous item, focus remains on the same focusable element
The carousel moves to the next item, focus remains on the same focusable element
Usage and accessibility checklist
Use this checklist to confirm the component has been configured and used correctly.
UX checklist
- Media within each slotted slide loads and displays correctly
- return-href points to a valid, sensible destination within the app's routing
Accessibility checklist
- 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