Skip to content

Commit ae66ba6

Browse files
committed
fix: hide desktop settings back button
1 parent 0c4face commit ae66ba6

3 files changed

Lines changed: 10 additions & 9 deletions

File tree

src/app/features/settings/Settings.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,7 @@ export function Settings({
242242
setLegacyActivePage(SettingsPages.GeneralPage);
243243
};
244244

245-
const shouldShowSectionBack =
246-
visibleSection !== null && (screenSize === ScreenSize.Mobile || visibleSection !== 'general');
245+
const shouldShowSectionBack = visibleSection !== null && screenSize === ScreenSize.Mobile;
247246
const sectionRequestBack = shouldShowSectionBack ? handleRequestBack : undefined;
248247

249248
return (

src/app/features/settings/SettingsRoute.test.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ describe('SettingsSectionPage', () => {
355355
).toEqual(['Back', 'Close']);
356356
});
357357

358-
it('supports custom title semantics and close label', () => {
358+
it('supports custom title semantics and close label without a desktop back button', () => {
359359
render(
360360
<ScreenSizeProvider value={ScreenSize.Desktop}>
361361
<SettingsSectionPage
@@ -369,7 +369,7 @@ describe('SettingsSectionPage', () => {
369369
);
370370

371371
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent('Keyboard Shortcuts');
372-
expect(screen.getByRole('button', { name: 'Back' })).toBeInTheDocument();
372+
expect(screen.queryByRole('button', { name: 'Back' })).not.toBeInTheDocument();
373373
expect(screen.getByRole('button', { name: 'Close keyboard shortcuts' })).toBeInTheDocument();
374374
});
375375

@@ -720,18 +720,17 @@ describe('Settings shallow route shell', () => {
720720
expect(screen.getByRole('heading', { name: 'Devices section' })).toBeInTheDocument();
721721
});
722722

723-
it('returns to general settings when desktop section back is clicked', async () => {
723+
it('does not show a desktop section back button in shallow settings', async () => {
724724
const user = userEvent.setup();
725725

726726
renderClientShell(ScreenSize.Desktop);
727727

728728
await user.click(screen.getByRole('button', { name: 'Open settings' }));
729729
await user.click(screen.getByRole('button', { name: 'Devices' }));
730-
await user.click(screen.getByRole('button', { name: 'Back' }));
731730

732731
expect(screen.getByRole('heading', { name: 'Home route' })).toBeInTheDocument();
733-
expect(screen.getByRole('heading', { name: 'General section' })).toBeInTheDocument();
734-
expect(screen.queryByRole('heading', { name: 'Devices section' })).not.toBeInTheDocument();
732+
expect(screen.getByRole('heading', { name: 'Devices section' })).toBeInTheDocument();
733+
expect(screen.queryByRole('button', { name: 'Back' })).not.toBeInTheDocument();
735734
});
736735

737736
it('closes a desktop shallow settings flow in one step after switching sections', async () => {

src/app/features/settings/SettingsSectionPage.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ReactNode } from 'react';
22
import { Box, Icon, IconButton, Icons, Text } from 'folds';
33
import { Page, PageHeader } from '$components/page';
4+
import { ScreenSize, useScreenSizeContext } from '$hooks/useScreenSize';
45
import { settingsHeader } from './styles.css';
56

67
type SettingsSectionPageProps = {
@@ -22,14 +23,16 @@ export function SettingsSectionPage({
2223
actionLabel,
2324
children,
2425
}: SettingsSectionPageProps) {
26+
const screenSize = useScreenSizeContext();
2527
const closeLabel = actionLabel ?? 'Close';
28+
const showBack = screenSize === ScreenSize.Mobile && requestBack;
2629

2730
return (
2831
<Page>
2932
<PageHeader className={settingsHeader}>
3033
<Box grow="Yes" gap="200">
3134
<Box grow="Yes" alignItems="Center" gap="200">
32-
{requestBack && (
35+
{showBack && (
3336
<IconButton aria-label={backLabel ?? 'Back'} onClick={requestBack} variant="Surface">
3437
<Icon src={Icons.ArrowLeft} />
3538
</IconButton>

0 commit comments

Comments
 (0)