diff --git a/components/language-chooser/react/common/language-chooser-react-hook/useLanguageChooser.ts b/components/language-chooser/react/common/language-chooser-react-hook/useLanguageChooser.ts index aecce2d..39ac231 100644 --- a/components/language-chooser/react/common/language-chooser-react-hook/useLanguageChooser.ts +++ b/components/language-chooser/react/common/language-chooser-react-hook/useLanguageChooser.ts @@ -30,7 +30,10 @@ export interface ILanguageChooser { script: IScript | undefined ) => void; selectUnlistedLanguage: () => void; - resetTo: (initialLanguageTag: string) => void; + resetTo: ( + initialLanguageTag: string, + initialCustomDisplayName?: string + ) => void; } export const useLanguageChooser = ( @@ -76,7 +79,10 @@ export const useLanguageChooser = ( // For reopening to a specific selection. We should then also set the search string // such that the selected language is visible. - function resetTo(initialLanguageTag: string) { + function resetTo( + initialLanguageTag: string, + initialCustomDisplayName?: string // all info can be captured in language tag except display name + ) { // clear everything setSelectedLanguage(undefined); setSelectedScript(undefined); @@ -90,8 +96,11 @@ export const useLanguageChooser = ( onSearchStringChange(initialSelections.language?.languageSubtag || ""); setSelectedLanguage(initialSelections.language); saveLanguageDetails( - initialSelections.customDetails || ({} as ICustomizableLanguageDetails), - initialSelections.script + { + ...initialSelections.customDetails, + displayName: initialCustomDisplayName, + } as ICustomizableLanguageDetails, + initialSelections?.script ); } } diff --git a/components/language-chooser/react/language-chooser-react-mui/src/LanguageChooser.tsx b/components/language-chooser/react/language-chooser-react-mui/src/LanguageChooser.tsx index a20ae96..e3e128a 100644 --- a/components/language-chooser/react/language-chooser-react-mui/src/LanguageChooser.tsx +++ b/components/language-chooser/react/language-chooser-react-mui/src/LanguageChooser.tsx @@ -50,6 +50,7 @@ export const LanguageChooser: React.FunctionComponent<{ searchString: string ) => ILanguage[]; initialLanguageTag?: string; + initialCustomDisplayName?: string; onClose: ( languageSelection: IOrthography | undefined, languageTag: string | undefined @@ -59,7 +60,7 @@ export const LanguageChooser: React.FunctionComponent<{ const lp: ILanguageChooser = useLanguageChooser(props.searchResultModifier); useEffect(() => { - lp.resetTo(props.initialLanguageTag || ""); + lp.resetTo(props.initialLanguageTag || "", props.initialCustomDisplayName); // We only want this to run once // eslint-disable-next-line react-hooks/exhaustive-deps }, []); diff --git a/components/language-chooser/react/language-chooser-react-mui/src/demos/DialogDemo.tsx b/components/language-chooser/react/language-chooser-react-mui/src/demos/DialogDemo.tsx index ace125b..38fffe4 100644 --- a/components/language-chooser/react/language-chooser-react-mui/src/demos/DialogDemo.tsx +++ b/components/language-chooser/react/language-chooser-react-mui/src/demos/DialogDemo.tsx @@ -204,6 +204,7 @@ export const DialogDemo: React.FunctionComponent<{