From 483be090418b1bc195528b4a12a71f91f3a229c5 Mon Sep 17 00:00:00 2001 From: splincode Date: Wed, 27 Nov 2024 13:38:56 +0300 Subject: [PATCH] fix: clear html socket view if empty content is passed --- projects/demo-playwright/tests/reset.spec.ts | 6 ++++++ .../components/editor-socket/editor-socket.component.ts | 8 ++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/projects/demo-playwright/tests/reset.spec.ts b/projects/demo-playwright/tests/reset.spec.ts index 0ac92d85f..06765f5b0 100644 --- a/projects/demo-playwright/tests/reset.spec.ts +++ b/projects/demo-playwright/tests/reset.spec.ts @@ -6,17 +6,23 @@ test.describe('Reset', () => { test('Correct reset value from wysiwyg', async ({page}) => { await tuiGoto(page, '/starter-kit?placeholder=Hello'); + await page.locator('tui-editor [contenteditable]').focus(); + await page.waitForTimeout(300); + await expect(page.locator('tui-editor')).toHaveScreenshot('Reset-01.png'); await page.locator('button:has-text("Reset")').click(); + await page.waitForTimeout(300); await expect(page.locator('tui-editor')).toHaveScreenshot('Reset-02.png'); await page.locator('tui-editor [contenteditable]').fill('12345'); + await page.waitForTimeout(300); await expect(page.locator('tui-editor')).toHaveScreenshot('Reset-03.png'); await page.locator('button:has-text("Reset")').click(); + await page.waitForTimeout(300); await expect(page.locator('tui-editor')).toHaveScreenshot('Reset-04.png'); }); diff --git a/projects/editor/components/editor-socket/editor-socket.component.ts b/projects/editor/components/editor-socket/editor-socket.component.ts index a426aa022..f8f87a661 100644 --- a/projects/editor/components/editor-socket/editor-socket.component.ts +++ b/projects/editor/components/editor-socket/editor-socket.component.ts @@ -36,13 +36,9 @@ export class TuiEditorSocket { protected readonly html = signal(null); @Input() - public set content(content: string | null) { - if (!content) { - return; - } - + public set content(content: string | null | undefined) { const safety = - this.customSanitizer?.sanitize(SecurityContext.HTML, content) ?? + this.customSanitizer?.sanitize(SecurityContext.HTML, content ?? '') ?? this.sanitizer.bypassSecurityTrustHtml(content ?? ''); this.html.set(safety);