From b0dee6d3faa2636c9511e805dbfeaa2a85876ddf Mon Sep 17 00:00:00 2001 From: Oliver Lazoroski Date: Thu, 2 Apr 2026 14:58:42 +0200 Subject: [PATCH 1/8] fix(ChannelHeader): hide toggle sidebar button when no ChannelList is rendered The expand button in ChannelHeader is pointless when there is no ChannelList in the component tree. Use the existing ChannelListContext to detect whether a ChannelList is present and conditionally render the button. --- src/components/Button/ToggleSidebarButton.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/components/Button/ToggleSidebarButton.tsx b/src/components/Button/ToggleSidebarButton.tsx index 6f44eccbae..707b0628e1 100644 --- a/src/components/Button/ToggleSidebarButton.tsx +++ b/src/components/Button/ToggleSidebarButton.tsx @@ -1,6 +1,10 @@ import React from 'react'; import { useIsMobileViewport } from '../ChannelHeader/hooks/useIsMobileViewport'; -import { useChatContext, useTranslationContext } from '../../context'; +import { + useChannelListContext, + useChatContext, + useTranslationContext, +} from '../../context'; import { Button, type ButtonProps } from './Button'; type ToggleSidebarButtonProps = ButtonProps & { @@ -19,7 +23,12 @@ export const ToggleSidebarButton = ({ const { t } = useTranslationContext('ChannelHeader'); const toggleNav = navOpen ? closeMobileNav : openMobileNav; const isMobileViewport = useIsMobileViewport(); - const showButton = mode === 'expand' ? isMobileViewport || !navOpen : canCollapse; + + const { channels } = useChannelListContext(); + const hasChannelList = !!channels; + + const sidebarCanExpand = hasChannelList && (isMobileViewport || !navOpen); + const showButton = mode === 'expand' ? sidebarCanExpand : !!canCollapse; return showButton ? ( + ); +}; + const language = new URLSearchParams(window.location.search).get('language'); const i18nInstance = language ? new Streami18n({ language: language as any }) : undefined; @@ -358,6 +392,7 @@ const App = () => { MessageReactions: CustomMessageReactions, reactionOptions: newReactionOptions, Search: CustomChannelSearch, + SidebarToggle, ...messageUiOverrides, }} > diff --git a/src/components/Button/ToggleSidebarButton.tsx b/src/components/Button/ToggleSidebarButton.tsx deleted file mode 100644 index 707b0628e1..0000000000 --- a/src/components/Button/ToggleSidebarButton.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import React from 'react'; -import { useIsMobileViewport } from '../ChannelHeader/hooks/useIsMobileViewport'; -import { - useChannelListContext, - useChatContext, - useTranslationContext, -} from '../../context'; -import { Button, type ButtonProps } from './Button'; - -type ToggleSidebarButtonProps = ButtonProps & { - /** expand mode is usually assigned to button, whose task is to show the sidebar, and collapse vice versa */ - mode: 'expand' | 'collapse'; - /** usually can collapse if an item from sidebar was selected */ - canCollapse?: boolean; -}; - -export const ToggleSidebarButton = ({ - canCollapse, - mode, - ...props -}: ToggleSidebarButtonProps) => { - const { closeMobileNav, navOpen, openMobileNav } = useChatContext('ChannelHeader'); - const { t } = useTranslationContext('ChannelHeader'); - const toggleNav = navOpen ? closeMobileNav : openMobileNav; - const isMobileViewport = useIsMobileViewport(); - - const { channels } = useChannelListContext(); - const hasChannelList = !!channels; - - const sidebarCanExpand = hasChannelList && (isMobileViewport || !navOpen); - const showButton = mode === 'expand' ? sidebarCanExpand : !!canCollapse; - - return showButton ? ( -