Skip to content

Commit

Permalink
fix: tabs condition (#707)
Browse files Browse the repository at this point in the history
  • Loading branch information
Juli Ovechkina authored Nov 21, 2023
1 parent 5604d29 commit 71b27ee
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/blocks/Tabs/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,30 @@ export const TabsBlock = ({
const mediaWidth = ref?.current?.offsetWidth;
const captionId = useUniqId();
const themedMedia = getThemedValue(activeTabData?.media, theme);
const hasNoImage = !themedMedia?.image || !activeTabData?.image;
const hasNoImage = !themedMedia?.image && !activeTabData?.image;
const mediaVideoHeight = hasNoImage && mediaWidth && getHeight(mediaWidth);
const [minImageHeight, setMinImageHeight] = useState(ref?.current?.offsetHeight);
// TODO remove property support activeTabData?.image. Use only activeTabData?.media?.image
let imageProps;

const handleImageHeight = useCallback(() => {
setMinImageHeight(ref?.current?.offsetHeight);
}, []);

const onSelectTab = (
id: string | null,
e: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement>,
) => {
setActiveTab(id);
handleImageHeight();
e.currentTarget.scrollIntoView({inline: 'center', behavior: 'smooth', block: 'nearest'});
};
if (minImageHeight !== ref?.current?.offsetHeight) {
setMinImageHeight(ref?.current?.offsetHeight);
}
}, [minImageHeight]);

const onSelectTab = useCallback(
(id: string | null, e: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => {
setActiveTab(id);
handleImageHeight();
e.currentTarget.scrollIntoView({
inline: 'center',
behavior: 'smooth',
block: 'nearest',
});
},
[handleImageHeight],
);

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

0 comments on commit 71b27ee

Please sign in to comment.