Skip to content

Commit

Permalink
fix: update value in read-only state on API call (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
anasmi committed Jul 16, 2020
1 parent 25480b5 commit 4b8cef7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/vaadin-rich-text-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
];

const SOURCE = {
API: 'api',
USER: 'user',
SILENT: 'silent'
};
Expand Down Expand Up @@ -874,7 +875,7 @@
*/
dangerouslySetHtmlValue(htmlValue) {
const deltaFromHtml = this._editor.clipboard.convert(htmlValue);
this._editor.setContents(deltaFromHtml, SOURCE.USER);
this._editor.setContents(deltaFromHtml, SOURCE.API);
}

/** @private */
Expand Down
10 changes: 10 additions & 0 deletions test/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,16 @@
expect(rte.hasAttribute('readonly')).to.be.true;
});

it('should update value on API call', () => {
rte.readonly = true;
rte.dangerouslySetHtmlValue('<h3><i>Foo</i>Bar</h3>');
flushValueDebouncer();
const delta = '[{"attributes":{"italic":true},"insert":"Foo"},{"insert":"Bar"},{"attributes":{"header":3},"insert":"\\n"}]';
expect(rte.value).to.equal(delta);
// Quill is converting the italic font to use appropriate tag
expect(rte.htmlValue).to.equal('<h3><em>Foo</em>Bar</h3>');
});

it('should invoke the editor methods', () => {
const spy = sinon.spy(editor, 'enable');
rte.readonly = true;
Expand Down

0 comments on commit 4b8cef7

Please sign in to comment.