-
Notifications
You must be signed in to change notification settings - Fork 294
feat!: externalize sidebar toggle and remove navOpen state from the SDK #3088
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
oliverlaz
merged 10 commits into
master
from
fix/hide-toggle-sidebar-without-channel-list
Apr 8, 2026
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b0dee6d
fix(ChannelHeader): hide toggle sidebar button when no ChannelList isβ¦
oliverlaz eb6cd45
test(ChannelHeader): add tests for toggle sidebar button visibility
oliverlaz 968e6f2
feat(ChannelHeader): make sidebar toggle an externally-provided compoβ¦
oliverlaz fdc986a
feat!: remove navOpen and sidebar state from the SDK
oliverlaz a0a9869
refactor: rename SidebarToggle slot to HeaderStartContent / HeaderEndβ¦
oliverlaz 0811b4d
fix(examples): remove unnecessary setTimeout from openSidebar
oliverlaz d6b0dc4
style: fix prettier formatting in SCSS files
oliverlaz 594930d
Merge branch 'master' into fix/hide-toggle-sidebar-without-channel-list
oliverlaz bf02004
Merge branch 'master' into fix/hide-toggle-sidebar-without-channel-list
oliverlaz 0bc0dbd
chore: remove missing import
oliverlaz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,23 @@ | ||
| import React, { type ComponentType } from 'react'; | ||
| import React from 'react'; | ||
| import clsx from 'clsx'; | ||
| import { useChatContext, useTranslationContext } from '../../context'; | ||
| import { IconSidebar } from '../Icons'; | ||
| import { ToggleSidebarButton } from '../Button/ToggleSidebarButton'; | ||
| import { | ||
| useChatContext, | ||
| useComponentContext, | ||
| useTranslationContext, | ||
| } from '../../context'; | ||
|
|
||
| export type ChannelListHeaderProps = { | ||
| ToggleButtonIcon?: ComponentType; | ||
| }; | ||
|
|
||
| export const ChannelListHeader = ({ | ||
| ToggleButtonIcon = IconSidebar, | ||
| }: ChannelListHeaderProps) => { | ||
| export const ChannelListHeader = () => { | ||
| const { t } = useTranslationContext(); | ||
| const { channel, navOpen } = useChatContext(); | ||
| const { SidebarToggle } = useComponentContext(); | ||
| return ( | ||
| <div | ||
| className={clsx('str-chat__channel-list__header', { | ||
| 'str-chat__channel-list__header--sidebar-collapsed': !navOpen, | ||
| })} | ||
| > | ||
| <div className='str-chat__channel-list__header__title'>{t('Chats')}</div> | ||
| <ToggleSidebarButton canCollapse={!!channel} mode={'collapse'}> | ||
| <ToggleButtonIcon /> | ||
| </ToggleSidebarButton> | ||
| {channel && SidebarToggle && <SidebarToggle />} | ||
| </div> | ||
| ); | ||
| }; |
53 changes: 53 additions & 0 deletions
53
src/components/ChannelList/__tests__/ChannelListHeader.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import React from 'react'; | ||
| import { cleanup, render, screen } from '@testing-library/react'; | ||
| import { ChatProvider, WithComponents } from '../../../context'; | ||
| import { TranslationProvider } from '../../../context/TranslationContext'; | ||
| import { mockChatContext, mockTranslationContextValue } from '../../../mock-builders'; | ||
| import { ChannelListHeader } from '../ChannelListHeader'; | ||
|
|
||
| const t = vi.fn((key: string) => key); | ||
| const SidebarToggle = () => <div data-testid='sidebar-toggle' />; | ||
|
|
||
| afterEach(cleanup); | ||
|
|
||
| describe('ChannelListHeader', () => { | ||
| it('should not render SidebarToggle when not provided via ComponentContext', () => { | ||
| render( | ||
| <ChatProvider value={mockChatContext()}> | ||
| <TranslationProvider value={mockTranslationContextValue({ t })}> | ||
| <ChannelListHeader /> | ||
| </TranslationProvider> | ||
| </ChatProvider>, | ||
| ); | ||
|
|
||
| expect(screen.queryByTestId('sidebar-toggle')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should render SidebarToggle when a channel is active', () => { | ||
| render( | ||
| <WithComponents overrides={{ SidebarToggle }}> | ||
| <ChatProvider value={mockChatContext({ channel: {} })}> | ||
| <TranslationProvider value={mockTranslationContextValue({ t })}> | ||
| <ChannelListHeader /> | ||
| </TranslationProvider> | ||
| </ChatProvider> | ||
| </WithComponents>, | ||
| ); | ||
|
|
||
| expect(screen.getByTestId('sidebar-toggle')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should not render SidebarToggle when no channel is active', () => { | ||
| render( | ||
| <WithComponents overrides={{ SidebarToggle }}> | ||
| <ChatProvider value={mockChatContext({ channel: undefined })}> | ||
| <TranslationProvider value={mockTranslationContextValue({ t })}> | ||
| <ChannelListHeader /> | ||
| </TranslationProvider> | ||
| </ChatProvider> | ||
| </WithComponents>, | ||
| ); | ||
|
|
||
| expect(screen.queryByTestId('sidebar-toggle')).not.toBeInTheDocument(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.