diff --git a/src/platform/plugins/private/presentation_panel/public/panel_actions/customize_panel_action/customize_panel_editor.test.tsx b/src/platform/plugins/private/presentation_panel/public/panel_actions/customize_panel_action/customize_panel_editor.test.tsx index 91be0c249be5..21633f28e821 100644 --- a/src/platform/plugins/private/presentation_panel/public/panel_actions/customize_panel_action/customize_panel_editor.test.tsx +++ b/src/platform/plugins/private/presentation_panel/public/panel_actions/customize_panel_action/customize_panel_editor.test.tsx @@ -89,6 +89,17 @@ describe('customize panel editor', () => { expect(titleInput).toHaveValue('Default title'); }); + // Even if the input value matches defaultTitle on apply, we expect setTitle(undefined) to be called, meaning the title is treated as "not customized". + it('should not set panel custom title if it matches default title on apply', async () => { + api.defaultTitle$ = new BehaviorSubject('Default title'); + renderPanelEditor(); + const titleInput = screen.getByTestId('customEmbeddablePanelTitleInput'); + expect(titleInput).toHaveValue('Default title'); + await userEvent.click(screen.getByTestId('saveCustomizePanelButton')); + expect(setTitle).toHaveBeenCalledWith(undefined); + expect(api.title$?.getValue()).toBeUndefined(); + }); + it('should use title even when empty string', () => { api.defaultTitle$ = new BehaviorSubject('Default title'); setTitle(''); diff --git a/src/platform/plugins/private/presentation_panel/public/panel_actions/customize_panel_action/customize_panel_editor.tsx b/src/platform/plugins/private/presentation_panel/public/panel_actions/customize_panel_action/customize_panel_editor.tsx index 122fd05e5309..4d8f41c60d47 100644 --- a/src/platform/plugins/private/presentation_panel/public/panel_actions/customize_panel_action/customize_panel_editor.tsx +++ b/src/platform/plugins/private/presentation_panel/public/panel_actions/customize_panel_action/customize_panel_editor.tsx @@ -99,7 +99,13 @@ export const CustomizePanelEditor = ({ const dateFormat = useMemo(() => core.uiSettings.get(UI_SETTINGS.DATE_FORMAT), []); const save = () => { - if (panelTitle !== api.title$?.value) api.setTitle?.(panelTitle); + // If the panel title matches the default title, we set api.title to undefined to indicate there's no custom title. + // This ensures the panel stays in sync with the centrally saved object's title and reflects any updates to its title. + if (panelTitle === api?.defaultTitle$?.value) { + api.setTitle?.(undefined); + } else if (panelTitle !== api.title$?.value) { + api.setTitle?.(panelTitle); + } if (hideTitle !== api.hideTitle$?.value) api.setHideTitle?.(hideTitle); if (panelDescription !== api.description$?.value) api.setDescription?.(panelDescription);