diff --git a/src/components/Gallery/__tests__/Gallery.test.tsx b/src/components/Gallery/__tests__/Gallery.test.tsx index 376d7af9..e719c8b0 100644 --- a/src/components/Gallery/__tests__/Gallery.test.tsx +++ b/src/components/Gallery/__tests__/Gallery.test.tsx @@ -1,6 +1,9 @@ +import {MobileProvider} from '@gravity-ui/uikit'; + import {fireEvent, render, screen} from '../../../../test-utils/utils'; import {Gallery} from '../Gallery'; import {GalleryItem} from '../GalleryItem'; +import {getGalleryItemDownloadAction} from '../utils/getGalleryItemDownloadAction'; const renderItems = () => [ Item A} thumbnail={thumb A} name="A" />, @@ -48,6 +51,34 @@ describe('Gallery', () => { }); }); + it.each([ + {device: 'desktop', mobile: false}, + {device: 'mobile', mobile: true}, + ])('should isolate the opener for a download link on $device', async ({mobile}) => { + const downloadUrl = 'https://example.test/image.png'; + + render( + + + Item A} + thumbnail={thumb A} + actions={[getGalleryItemDownloadAction({downloadUrl})]} + /> + + , + ); + + if (mobile) { + fireEvent.click(screen.getByRole('button', {name: 'Close'})); + } + const link = await screen.findByRole('link', {name: 'Download'}); + + expect(link).toHaveAttribute('href', downloadUrl); + expect(link).toHaveAttribute('target', '_blank'); + expect(link).toHaveAttribute('rel', 'noopener noreferrer'); + }); + describe('inline view', () => { it('should render the content without a Modal, regardless of open', () => { render({renderItems()}); diff --git a/src/components/Gallery/components/DesktopGalleryHeader/DesktopGalleryHeader.tsx b/src/components/Gallery/components/DesktopGalleryHeader/DesktopGalleryHeader.tsx index c30725e4..39ad0ef0 100644 --- a/src/components/Gallery/components/DesktopGalleryHeader/DesktopGalleryHeader.tsx +++ b/src/components/Gallery/components/DesktopGalleryHeader/DesktopGalleryHeader.tsx @@ -75,7 +75,10 @@ export const DesktopGalleryHeader = ({ view: 'flat', onClick: action.onClick, href: action.href, - target: '__blank', + ...(action.href !== undefined && { + target: '_blank', + rel: 'noopener noreferrer', + }), 'aria-label': title, children: action.icon, }; diff --git a/src/components/Gallery/components/MobileGalleryActions/MobileGalleryActions.tsx b/src/components/Gallery/components/MobileGalleryActions/MobileGalleryActions.tsx index 684478f6..4f1e66bf 100644 --- a/src/components/Gallery/components/MobileGalleryActions/MobileGalleryActions.tsx +++ b/src/components/Gallery/components/MobileGalleryActions/MobileGalleryActions.tsx @@ -33,7 +33,7 @@ export const MobileGalleryActions = ({open, actions = [], onClose}: MobileGaller view: 'flat', onClick: item.onClick, href: item.href, - target: '__blank', + ...(item.href !== undefined && {target: '_blank', rel: 'noopener noreferrer'}), 'aria-label': title, className: cnMobileGalleryActions('list-item'), width: 'max',