Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: the value in the component is incorrectly updated when it is passed as an empty string using formControl #1558

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions projects/demo-playwright/tests/reset.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {expect, test} from '@playwright/test';

import {tuiGoto} from '../utils';

test.describe('Reset', () => {
test('Correct reset value from wysiwyg', async ({page}) => {
await tuiGoto(page, '/starter-kit?placeholder=Hello');

await expect(page.locator('tui-editor')).toHaveScreenshot('Reset-01.png');

await page.locator('button:has-text("Reset")').click();

await expect(page.locator('tui-editor')).toHaveScreenshot('Reset-02.png');

await page.locator('tui-editor [contenteditable]').fill('12345');

await expect(page.locator('tui-editor')).toHaveScreenshot('Reset-03.png');

await page.locator('button:has-text("Reset")').click();

await expect(page.locator('tui-editor')).toHaveScreenshot('Reset-04.png');
});
});
1 change: 0 additions & 1 deletion projects/editor/components/editor/editor.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
tuiTiptapEditor
class="tui-editor-socket"
[editable]="interactive()"
[value]="firstInitialValue"
(valueChange)="onModelChange($event)"
></div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions projects/editor/components/editor/editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export class TuiEditor extends TuiControl<string> implements OnDestroy {

this.patchContentEditableElement();
this.listenResizeEvents();
this.editorService.setValue(this.firstInitialValue);
this.editorLoaded.set(true);
});

Expand Down Expand Up @@ -235,6 +236,10 @@ export class TuiEditor extends TuiControl<string> implements OnDestroy {
if (!this.focused()) {
this.doc?.getSelection?.()?.removeAllRanges();
}

if (this.editorLoaded()) {
this.editorService.setValue(processed ?? '');
}
}

public ngOnDestroy(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@ export class TuiTiptapEditor {

protected editorContainer = inject(INITIALIZATION_TIPTAP_CONTAINER);

protected readonly $ = inject(TIPTAP_EDITOR)
.pipe(takeUntilDestroyed())
.subscribe(() =>
this.renderer.appendChild(this.el.nativeElement, this.editorContainer),
);

@Output()
public readonly valueChange = this.editor.valueChange$;

@Output()
public readonly stateChange = this.editor.stateChange$;

constructor() {
inject(TIPTAP_EDITOR)
.pipe(takeUntilDestroyed())
.subscribe(() =>
this.renderer.appendChild(this.el.nativeElement, this.editorContainer),
);
}

@Input()
public set value(value: string) {
this.editor.setValue(value);
Expand Down
Loading