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: remove event listeners when component is destroyed #1947

Merged
Merged
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
12 changes: 7 additions & 5 deletions projects/ngx-quill/src/lib/quill-editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,17 +303,19 @@ export abstract class QuillEditorBase implements AfterViewInit, ControlValueAcce

if (this.onNativeBlur.observed) {
// https://github.com/quilljs/quill/issues/2186#issuecomment-533401328
this.quillEditor.scroll.domNode.addEventListener('blur', () => this.onNativeBlur.next({
fromEvent(this.quillEditor.scroll.domNode, 'blur').pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => this.onNativeBlur.next({
editor: this.quillEditor,
source: 'dom'
}))
// https://github.com/quilljs/quill/issues/2186#issuecomment-803257538
const toolbar = this.quillEditor.getModule('toolbar') as Toolbar
toolbar.container?.addEventListener('mousedown', (e) => e.preventDefault())
if (toolbar.container) {
fromEvent(toolbar.container, 'mousedown').pipe(takeUntilDestroyed(this.destroyRef)).subscribe(e => e.preventDefault())
}
}

if (this.onNativeFocus.observed) {
this.quillEditor.scroll.domNode.addEventListener('focus', () => this.onNativeFocus.next({
fromEvent(this.quillEditor.scroll.domNode, 'focus').pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => this.onNativeFocus.next({
editor: this.quillEditor,
source: 'dom'
}))
Expand All @@ -340,7 +342,7 @@ export abstract class QuillEditorBase implements AfterViewInit, ControlValueAcce
this.quillEditor.setContents(newValue, 'silent')
}

const history = this.quillEditor.getModule('history') as History
const history = this.quillEditor.getModule('history') as History
history.clear()
}

Expand Down Expand Up @@ -769,4 +771,4 @@ export abstract class QuillEditorBase implements AfterViewInit, ControlValueAcce
],
standalone: true
})
export class QuillEditorComponent extends QuillEditorBase {}
export class QuillEditorComponent extends QuillEditorBase { }