Skip to content

Commit

Permalink
Merge pull request #3430 from ONEARMY/fix/hide-thumbnails-for-single-…
Browse files Browse the repository at this point in the history
…image

fix: hide thumbnail for single image
  • Loading branch information
benfurber authored Apr 8, 2024
2 parents 4b95f4d + a10e9d8 commit ca8ddc9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/components/src/ImageGallery/ImageGallery.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ export const NoThumbnails: StoryFn<typeof ImageGallery> = (
return <ImageGallery images={testImages} {...props} hideThumbnails />
}

export const HideThumbnailForSingleImage: StoryFn<typeof ImageGallery> = (
props: Omit<ImageGalleryProps, 'images'>,
) => {
return <ImageGallery images={[testImages[0]]} {...props} />
}

export const ShowNextPrevButtons: StoryFn<typeof ImageGallery> = (
props: Omit<ImageGalleryProps, 'images'>,
) => {
Expand Down
13 changes: 13 additions & 0 deletions packages/components/src/ImageGallery/ImageGallery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ImageGallery } from './ImageGallery'
import {
Default,
DoNotShowNextPrevButtons,
HideThumbnailForSingleImage,
NoThumbnails,
ShowNextPrevButtons,
testImages,
Expand Down Expand Up @@ -153,6 +154,18 @@ describe('ImageGallery', () => {
expect(image?.getAttribute('src')).toEqual(testImages[0].downloadUrl)
})

it('hides thumbnail for single image', async () => {
const { getAllByTestId } = render(
<HideThumbnailForSingleImage
{...(HideThumbnailForSingleImage.args as ImageGalleryProps)}
/>,
)

expect(() => {
getAllByTestId('thumbnail')
}).toThrow()
})

it('supports no thumbnail option', async () => {
const { getAllByTestId } = render(
<NoThumbnails {...(NoThumbnails.args as ImageGalleryProps)} />,
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/ImageGallery/ImageGallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const ImageGallery = (props: ImageGalleryProps) => {
const activeImageIndex = state.activeImageIndex
const activeImage = images[activeImageIndex]
const imageNumber = images.length
const showThumbnails = !props.hideThumbnails && images.length >= 1
const showThumbnails = !props.hideThumbnails && images.length > 1
const showNextPrevButton = !!props.showNextPrevButton && images.length > 1

return activeImage ? (
Expand Down

0 comments on commit ca8ddc9

Please sign in to comment.