mirror of
https://github.com/langgenius/dify.git
synced 2026-04-05 20:09:20 +08:00
fix: keep account dropdown open when switching theme (#32918)
This commit is contained in:
@@ -13,44 +13,50 @@ export default function ThemeSwitcher() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center rounded-[10px] bg-components-segmented-control-bg-normal p-0.5">
|
<div className="flex items-center rounded-[10px] bg-components-segmented-control-bg-normal p-0.5">
|
||||||
<div
|
<button
|
||||||
|
type="button"
|
||||||
className={cn(
|
className={cn(
|
||||||
'rounded-lg px-2 py-1 text-text-tertiary hover:bg-state-base-hover hover:text-text-secondary',
|
'rounded-lg px-2 py-1 text-text-tertiary hover:bg-state-base-hover hover:text-text-secondary',
|
||||||
theme === 'system' && 'bg-components-segmented-control-item-active-bg text-text-accent-light-mode-only shadow-sm hover:bg-components-segmented-control-item-active-bg hover:text-text-accent-light-mode-only',
|
theme === 'system' && 'bg-components-segmented-control-item-active-bg text-text-accent-light-mode-only shadow-sm hover:bg-components-segmented-control-item-active-bg hover:text-text-accent-light-mode-only',
|
||||||
)}
|
)}
|
||||||
onClick={() => handleThemeChange('system')}
|
onClick={() => handleThemeChange('system')}
|
||||||
|
aria-label="System theme"
|
||||||
data-testid="system-theme-container"
|
data-testid="system-theme-container"
|
||||||
>
|
>
|
||||||
<div className="p-0.5">
|
<div className="p-0.5">
|
||||||
<span className="i-ri-computer-line h-4 w-4" />
|
<span className="i-ri-computer-line h-4 w-4" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</button>
|
||||||
<div className={cn('h-[14px] w-px bg-transparent', theme === 'dark' && 'bg-divider-regular')} data-testid="divider"></div>
|
<div className={cn('h-[14px] w-px bg-transparent', theme === 'dark' && 'bg-divider-regular')} data-testid="divider"></div>
|
||||||
<div
|
<button
|
||||||
|
type="button"
|
||||||
className={cn(
|
className={cn(
|
||||||
'rounded-lg px-2 py-1 text-text-tertiary hover:bg-state-base-hover hover:text-text-secondary',
|
'rounded-lg px-2 py-1 text-text-tertiary hover:bg-state-base-hover hover:text-text-secondary',
|
||||||
theme === 'light' && 'bg-components-segmented-control-item-active-bg text-text-accent-light-mode-only shadow-sm hover:bg-components-segmented-control-item-active-bg hover:text-text-accent-light-mode-only',
|
theme === 'light' && 'bg-components-segmented-control-item-active-bg text-text-accent-light-mode-only shadow-sm hover:bg-components-segmented-control-item-active-bg hover:text-text-accent-light-mode-only',
|
||||||
)}
|
)}
|
||||||
onClick={() => handleThemeChange('light')}
|
onClick={() => handleThemeChange('light')}
|
||||||
|
aria-label="Light theme"
|
||||||
data-testid="light-theme-container"
|
data-testid="light-theme-container"
|
||||||
>
|
>
|
||||||
<div className="p-0.5">
|
<div className="p-0.5">
|
||||||
<span className="i-ri-sun-line h-4 w-4" />
|
<span className="i-ri-sun-line h-4 w-4" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</button>
|
||||||
<div className={cn('h-[14px] w-px bg-transparent', theme === 'system' && 'bg-divider-regular')} data-testid="divider"></div>
|
<div className={cn('h-[14px] w-px bg-transparent', theme === 'system' && 'bg-divider-regular')} data-testid="divider"></div>
|
||||||
<div
|
<button
|
||||||
|
type="button"
|
||||||
className={cn(
|
className={cn(
|
||||||
'rounded-lg px-2 py-1 text-text-tertiary hover:bg-state-base-hover hover:text-text-secondary',
|
'rounded-lg px-2 py-1 text-text-tertiary hover:bg-state-base-hover hover:text-text-secondary',
|
||||||
theme === 'dark' && 'bg-components-segmented-control-item-active-bg text-text-accent-light-mode-only shadow-sm hover:bg-components-segmented-control-item-active-bg hover:text-text-accent-light-mode-only',
|
theme === 'dark' && 'bg-components-segmented-control-item-active-bg text-text-accent-light-mode-only shadow-sm hover:bg-components-segmented-control-item-active-bg hover:text-text-accent-light-mode-only',
|
||||||
)}
|
)}
|
||||||
onClick={() => handleThemeChange('dark')}
|
onClick={() => handleThemeChange('dark')}
|
||||||
|
aria-label="Dark theme"
|
||||||
data-testid="dark-theme-container"
|
data-testid="dark-theme-container"
|
||||||
>
|
>
|
||||||
<div className="p-0.5">
|
<div className="p-0.5">
|
||||||
<span className="i-ri-moon-line h-4 w-4" />
|
<span className="i-ri-moon-line h-4 w-4" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,10 @@ vi.mock('@/app/components/header/github-star', () => ({
|
|||||||
default: () => <div data-testid="github-star">GithubStar</div>,
|
default: () => <div data-testid="github-star">GithubStar</div>,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
vi.mock('@/app/components/base/theme-switcher', () => ({
|
||||||
|
default: () => <button type="button" data-testid="theme-switcher-button">Theme switcher</button>,
|
||||||
|
}))
|
||||||
|
|
||||||
vi.mock('@/context/app-context', () => ({
|
vi.mock('@/context/app-context', () => ({
|
||||||
useAppContext: vi.fn(),
|
useAppContext: vi.fn(),
|
||||||
}))
|
}))
|
||||||
@@ -276,6 +280,16 @@ describe('AccountDropdown', () => {
|
|||||||
// Assert
|
// Assert
|
||||||
expect(screen.queryByTestId('account-about')).not.toBeInTheDocument()
|
expect(screen.queryByTestId('account-about')).not.toBeInTheDocument()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should keep account dropdown open when clicking the theme switcher', () => {
|
||||||
|
// Act
|
||||||
|
renderWithRouter(<AppSelector />)
|
||||||
|
fireEvent.click(screen.getByRole('button', { name: 'common.account.account' }))
|
||||||
|
fireEvent.click(screen.getByTestId('theme-switcher-button'))
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(screen.getByText('common.userProfile.logout')).toBeInTheDocument()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Branding and Environment', () => {
|
describe('Branding and Environment', () => {
|
||||||
|
|||||||
@@ -228,8 +228,8 @@ export default function AppSelector() {
|
|||||||
)}
|
)}
|
||||||
<AccountMenuSection>
|
<AccountMenuSection>
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
|
closeOnClick={false}
|
||||||
className="cursor-default data-[highlighted]:bg-transparent"
|
className="cursor-default data-[highlighted]:bg-transparent"
|
||||||
onSelect={e => e.preventDefault()}
|
|
||||||
>
|
>
|
||||||
<MenuItemContent
|
<MenuItemContent
|
||||||
iconClassName="i-ri-t-shirt-2-line"
|
iconClassName="i-ri-t-shirt-2-line"
|
||||||
|
|||||||
Reference in New Issue
Block a user