Skip to content

Commit

Permalink
fix: refactor minHeight calculating (#866)
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaCG authored Mar 21, 2024
1 parent cd24fed commit ab0e32a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/blocks/Tabs/Tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {Fragment, useCallback, useRef, useState} from 'react';
import React, {Fragment, useCallback, useEffect, useRef, useState} from 'react';

import {useUniqId} from '@gravity-ui/uikit';

Expand Down Expand Up @@ -56,16 +56,19 @@ export const TabsBlock = ({
const onSelectTab = useCallback(
(id: string | null, e: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => {
setActiveTab(id);
handleImageHeight();
e.currentTarget.scrollIntoView({
inline: 'center',
behavior: 'smooth',
block: 'nearest',
});
},
[handleImageHeight],
[],
);

useEffect(() => {
handleImageHeight();
}, [activeTab, handleImageHeight]);

if (activeTabData) {
const themedImage = getThemedValue(activeTabData?.image, theme);

Expand Down Expand Up @@ -102,8 +105,8 @@ export const TabsBlock = ({
}}
className={b('col', {centered: centered})}
>
<div style={{minHeight: mediaVideoHeight || minImageHeight}}>
{activeTabData?.media && (
{activeTabData?.media && (
<div style={{minHeight: mediaVideoHeight || minImageHeight}}>
<div ref={ref}>
<Media
{...getThemedValue(activeTabData.media, theme)}
Expand All @@ -114,8 +117,8 @@ export const TabsBlock = ({
onImageLoad={handleImageHeight}
/>
</div>
)}
</div>
</div>
)}
{imageProps && (
<Fragment>
<FullscreenImage {...imageProps} imageClassName={b('image', {border})} />
Expand Down

0 comments on commit ab0e32a

Please sign in to comment.