diff --git a/services/web/frontend/extracted-translations.json b/services/web/frontend/extracted-translations.json index ba407863b5..d0672646f9 100644 --- a/services/web/frontend/extracted-translations.json +++ b/services/web/frontend/extracted-translations.json @@ -183,6 +183,7 @@ "center": "", "change": "", "change_currency": "", + "change_language": "", "change_or_cancel-cancel": "", "change_or_cancel-change": "", "change_or_cancel-or": "", diff --git a/services/web/frontend/js/features/editor-left-menu/components/editor-left-menu-context.tsx b/services/web/frontend/js/features/editor-left-menu/components/editor-left-menu-context.tsx new file mode 100644 index 0000000000..8682b056ec --- /dev/null +++ b/services/web/frontend/js/features/editor-left-menu/components/editor-left-menu-context.tsx @@ -0,0 +1,44 @@ +import { createContext, FC, useCallback, useContext, useState } from 'react' +import useEventListener from '@/shared/hooks/use-event-listener' + +type EditorLeftMenuState = { + settingToFocus?: string +} + +export const EditorLeftMenuContext = createContext< + EditorLeftMenuState | undefined +>(undefined) + +export const EditorLeftMenuProvider: FC = ({ children }) => { + const [value, setValue] = useState(() => ({ + settingToFocus: undefined, + })) + + useEventListener( + 'ui.focus-setting', + useCallback(event => { + setValue(value => ({ + ...value, + settingToFocus: (event as CustomEvent).detail, + })) + }, []) + ) + + return ( + + {children} + + ) +} + +export const useEditorLeftMenuContext = () => { + const value = useContext(EditorLeftMenuContext) + + if (!value) { + throw new Error( + `useEditorLeftMenuContext is only available inside EditorLeftMenuProvider` + ) + } + + return value +} diff --git a/services/web/frontend/js/features/editor-left-menu/components/editor-left-menu.tsx b/services/web/frontend/js/features/editor-left-menu/components/editor-left-menu.tsx index 73dea63d23..6564eaf27a 100644 --- a/services/web/frontend/js/features/editor-left-menu/components/editor-left-menu.tsx +++ b/services/web/frontend/js/features/editor-left-menu/components/editor-left-menu.tsx @@ -7,6 +7,8 @@ import { lazy, memo, Suspense } from 'react' import { FullSizeLoadingSpinner } from '@/shared/components/loading-spinner' import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher' import { Offcanvas } from 'react-bootstrap-5' +import { EditorLeftMenuProvider } from './editor-left-menu-context' + const EditorLeftMenuBody = lazy(() => import('./editor-left-menu-body')) function EditorLeftMenu() { @@ -19,7 +21,7 @@ function EditorLeftMenu() { return ( + {leftMenuShown && } - + } bs5={ - <> + {leftMenuShown && } - + } /> ) diff --git a/services/web/frontend/js/features/editor-left-menu/components/settings/settings-menu-select.tsx b/services/web/frontend/js/features/editor-left-menu/components/settings/settings-menu-select.tsx index 43bbf1648d..1cffe06fe9 100644 --- a/services/web/frontend/js/features/editor-left-menu/components/settings/settings-menu-select.tsx +++ b/services/web/frontend/js/features/editor-left-menu/components/settings/settings-menu-select.tsx @@ -2,8 +2,9 @@ import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/boots import OLFormGroup from '@/features/ui/components/ol/ol-form-group' import OLFormLabel from '@/features/ui/components/ol/ol-form-label' import OLFormSelect from '@/features/ui/components/ol/ol-form-select' -import { ChangeEventHandler, useCallback } from 'react' +import { ChangeEventHandler, useCallback, useEffect, useRef } from 'react' import { Spinner } from 'react-bootstrap-5' +import { useEditorLeftMenuContext } from '@/features/editor-left-menu/components/editor-left-menu-context' type PossibleValue = string | number | boolean @@ -54,6 +55,25 @@ export default function SettingsMenuSelect({ [onChange, value] ) + const { settingToFocus } = useEditorLeftMenuContext() + + const selectRef = useRef(null) + + useEffect(() => { + if (settingToFocus === name && selectRef.current) { + selectRef.current.scrollIntoView({ + block: 'center', + behavior: 'smooth', + }) + selectRef.current.focus() + } + + // clear the focus setting + window.dispatchEvent( + new CustomEvent('ui.focus-setting', { detail: undefined }) + ) + }, [name, settingToFocus]) + return ( ({ onChange={handleChange} value={value?.toString()} disabled={disabled} + ref={selectRef} > {options.map(option => (