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 change event #122

Merged
merged 1 commit into from
Aug 27, 2019
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
9 changes: 7 additions & 2 deletions src/vaadin-rich-text-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -675,9 +675,14 @@
}

__emitChangeEvent() {
this.__debounceSetValue && this.__debounceSetValue.flush();
let lastCommittedChange = this.__lastCommittedChange;

if (this.__lastCommittedChange !== this.value) {
if (this.__debounceSetValue && this.__debounceSetValue.isActive()) {
lastCommittedChange = this.value;
this.__debounceSetValue.flush();
}

if (lastCommittedChange !== this.value) {
this.dispatchEvent(new CustomEvent('change', {bubbles: true, cancelable: false}));
this.__lastCommittedChange = this.value;
}
Expand Down
6 changes: 6 additions & 0 deletions test/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,9 @@
// Emulate setting the value from keyboard
editor.focus();
setContent('Foo');
// Setting selection range to null in Quill
// Needed for proper hasFocus() check
content.blur();
content.dispatchEvent(new CustomEvent('focusout'));

expect(spy).to.be.calledOnce;
Expand All @@ -454,6 +457,7 @@

rte.value = JSON.stringify([{insert: 'Foo\n'}]);
editor.focus();
content.blur();
content.dispatchEvent(new CustomEvent('focusout'));

expect(spy).to.not.be.called;
Expand All @@ -475,6 +479,7 @@
btn.dispatchEvent(new MouseEvent('mousedown', {bubbles: true}));
const evt = new CustomEvent('focusout');
evt.relatedTarget = btn;
content.blur();
content.dispatchEvent(evt);
btn.click();

Expand Down Expand Up @@ -533,6 +538,7 @@
btn.dispatchEvent(new MouseEvent('mousedown', {bubbles: true}));
btn.click();

content.blur();
content.dispatchEvent(new CustomEvent('focusout'));

expect(spy).to.not.be.called;
Expand Down