From 592b07cd8ff0acbb89ee011d3fc6e6270f177b51 Mon Sep 17 00:00:00 2001 From: Erwan Leboucher Date: Fri, 7 Aug 2026 08:31:09 +0200 Subject: [PATCH] feat(settings): add search bar to settings sidebar --- .changeset/add-settings-search.md | 5 ++ src/app/components/SettingsShell.tsx | 60 ++++++++++++--------- src/app/features/settings/Settings.tsx | 59 +++++++++++++++++++- src/app/features/settings/SettingsRoute.tsx | 8 +++ src/app/features/settings/settingsLink.ts | 2 +- src/app/features/settings/settingsSearch.ts | 30 +++++++++++ 6 files changed, 136 insertions(+), 28 deletions(-) create mode 100644 .changeset/add-settings-search.md create mode 100644 src/app/features/settings/settingsSearch.ts diff --git a/.changeset/add-settings-search.md b/.changeset/add-settings-search.md new file mode 100644 index 000000000..34a248b67 --- /dev/null +++ b/.changeset/add-settings-search.md @@ -0,0 +1,5 @@ +--- +sable: minor +--- + +Add a search bar to the settings sidebar. diff --git a/src/app/components/SettingsShell.tsx b/src/app/components/SettingsShell.tsx index b02699151..57be2e6e2 100644 --- a/src/app/components/SettingsShell.tsx +++ b/src/app/components/SettingsShell.tsx @@ -28,6 +28,8 @@ export type SettingsShellProps = { renderHeader?: (closeButton: ReactNode) => ReactNode; /** Render custom footer below the menu (inside the PageNav column). */ footer?: ReactNode; + searchBar?: ReactNode; + searchResults?: ReactNode; /** Optional wrapper rendered around the entire component (e.g. SwipeableOverlayWrapper). */ wrapper?: (children: ReactNode) => ReactNode; /** Wrap the section viewport content (e.g. SettingsLinkProvider). Receives the viewport element. */ @@ -66,6 +68,8 @@ export function SettingsShell({ requestClose, renderHeader, footer, + searchBar, + searchResults, wrapper, renderSection, showCloseInHeader, @@ -104,35 +108,41 @@ export function SettingsShell({ )} + {searchBar && ( + + {searchBar} + + )}
- {visibleIds.map((id) => { - const section = sections[id]; - const isActive = active === id; - const IconComponent = - isActive && section.activeIcon ? section.activeIcon : section.icon; + {searchResults ?? + visibleIds.map((id) => { + const section = sections[id]; + const isActive = active === id; + const IconComponent = + isActive && section.activeIcon ? section.activeIcon : section.icon; - return ( - onSelect(id)} - > - onSelect(id)} > - {section.label} - - - ); - })} + + {section.label} + + + ); + })}
{footer} diff --git a/src/app/features/settings/Settings.tsx b/src/app/features/settings/Settings.tsx index cc7af5e3d..1b37a7837 100644 --- a/src/app/features/settings/Settings.tsx +++ b/src/app/features/settings/Settings.tsx @@ -1,7 +1,7 @@ import { useMemo, useState } from 'react'; import type { ComponentType, ReactNode } from 'react'; import { DesktopIcon, PersonSimpleCircleIcon, type IconProps } from '@phosphor-icons/react'; -import { Avatar, Box, Button, config, Text } from 'folds'; +import { Avatar, Box, Button, config, Input, MenuItem, Text } from 'folds'; import { ScreenSize, useScreenSizeContext } from '$hooks/useScreenSize'; import { useUserProfile } from '$hooks/useUserProfile'; import { useMatrixClient } from '$hooks/useMatrixClient'; @@ -20,9 +20,11 @@ import { GearSix, Info, Keyboard, + MagnifyingGlass, menuIcon, SignOut, Palette, + sizedIcon, Smiley, Terminal, User, @@ -41,6 +43,7 @@ import { KeyboardShortcuts } from './keyboard-shortcuts'; import { Notifications } from './notifications'; import { PerMessageProfilePage } from './Persona/ProfilesPage'; import { settingsSections, type SettingsSectionId } from './routes'; +import { searchSettings, type SettingsSearchEntry } from './settingsSearch'; import { useSettingsFocus } from './useSettingsFocus'; import { SettingsLinkProvider } from './SettingsLinkContext'; import { useSettingsLinkBaseUrl } from './useSettingsLinkBaseUrl'; @@ -146,6 +149,7 @@ const settingsSectionComponents = { type ControlledSettingsProps = { activeSection?: SettingsSectionId | null; onSelectSection?: (section: SettingsSectionId) => void; + onSelectSetting?: (section: SettingsSectionId, focus: string) => void; onBack?: () => void; requestClose: () => void; initialPage?: SettingsPages; @@ -165,6 +169,7 @@ function SettingsSectionProvider({ children, section, baseUrl }: SectionWrapperP export function Settings({ activeSection, onSelectSection, + onSelectSetting, onBack, requestClose, initialPage, @@ -273,6 +278,16 @@ export function Settings({ [showPersona, isDesktop] ); + const [searchQuery, setSearchQuery] = useState(''); + const searchResults = useMemo(() => searchSettings(searchQuery), [searchQuery]); + const isSearching = searchQuery.trim().length > 0; + const menuItemTextSize = screenSize === ScreenSize.Mobile ? 'T400' : 'T300'; + + const handleSearchResultSelect = (entry: SettingsSearchEntry) => { + setSearchQuery(''); + onSelectSetting?.(entry.section, entry.focusId); + }; + const renderHeader = useMemo( () => (closeButton: ReactNode): ReactNode => ( @@ -305,8 +320,48 @@ export function Settings({ requestClose={handleRequestClose} renderHeader={renderHeader} showCloseInHeader={visibleSection === null} - menuItemTextSize={screenSize === ScreenSize.Mobile ? 'T400' : 'T300'} + menuItemTextSize={menuItemTextSize} closeButtonAriaLabel="Close settings" + searchBar={ + setSearchQuery((e.target as HTMLInputElement).value)} + before={sizedIcon(MagnifyingGlass, '50')} + style={{ width: '100%' }} + /> + } + searchResults={ + isSearching ? ( + searchResults.length > 0 ? ( + searchResults.map((entry) => ( + handleSearchResultSelect(entry)} + > + + + {entry.label} + + + {entry.sectionLabel} + + + + )) + ) : ( + + No results found + + ) + ) : undefined + } renderSection={(viewport) => visibleSection ? ( diff --git a/src/app/features/settings/SettingsRoute.tsx b/src/app/features/settings/SettingsRoute.tsx index 8d060db57..f61b84f25 100644 --- a/src/app/features/settings/SettingsRoute.tsx +++ b/src/app/features/settings/SettingsRoute.tsx @@ -133,11 +133,19 @@ export function SettingsRoute({ routeSection }: SettingsRouteProps) { }); }; + const handleSelectSetting = (nextSection: SettingsSectionId, focus: string) => { + navigate(getSettingsPath(nextSection, focus), { + replace: shallowBackgroundState, + state: location.state, + }); + }; + return ( ); diff --git a/src/app/features/settings/settingsLink.ts b/src/app/features/settings/settingsLink.ts index 651ecd352..469dddf1a 100644 --- a/src/app/features/settings/settingsLink.ts +++ b/src/app/features/settings/settingsLink.ts @@ -416,7 +416,7 @@ export const buildSettingsLink = ( focus?: string ): string => withOriginBaseUrl(baseUrl, withSettingsLinkAction(getSettingsPath(section, focus))); -const humanizeSettingsLinkPart = (value: string): string => +export const humanizeSettingsLinkPart = (value: string): string => value .split(/[^a-zA-Z0-9]+/) .filter(Boolean) diff --git a/src/app/features/settings/settingsSearch.ts b/src/app/features/settings/settingsSearch.ts new file mode 100644 index 000000000..701c3b8b1 --- /dev/null +++ b/src/app/features/settings/settingsSearch.ts @@ -0,0 +1,30 @@ +import { settingsSections, type SettingsSectionId } from './routes'; +import { humanizeSettingsLinkPart, settingsLinkFocusIdsBySection } from './settingsLink'; + +export type SettingsSearchEntry = { + section: SettingsSectionId; + focusId: string; + label: string; + sectionLabel: string; +}; + +const settingsSectionLabel = Object.fromEntries( + settingsSections.map((section) => [section.id, section.label]) +) as Record; + +const searchIndex: SettingsSearchEntry[] = settingsSections.flatMap((section) => + settingsLinkFocusIdsBySection[section.id].map((focusId) => ({ + section: section.id, + focusId, + label: humanizeSettingsLinkPart(focusId), + sectionLabel: settingsSectionLabel[section.id], + })) +); + +export const searchSettings = (query: string): SettingsSearchEntry[] => { + const q = query.trim().toLowerCase(); + if (!q) return []; + return searchIndex.filter( + (entry) => entry.label.toLowerCase().includes(q) || entry.sectionLabel.toLowerCase().includes(q) + ); +};