Skip to content

Commit

Permalink
fix: do not throw when dir attribute is set initially (#6996) (#6998)
Browse files Browse the repository at this point in the history
Co-authored-by: Sergey Vinogradov <mr.vursen@gmail.com>
  • Loading branch information
vaadin-bot and vursen authored Dec 22, 2023
1 parent 56f7a8f commit c94de89
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ export const RichTextEditorMixin = (superClass) =>

/** @private */
__setDirection(dir) {
if (!this._editor) {
return;
}

// Needed for proper `ql-align` class to be set and activate the toolbar align button
const alignAttributor = Quill.import('attributors/class/align');
alignAttributor.whitelist = [dir === 'rtl' ? 'left' : 'right', 'center', 'justify'];
Expand Down Expand Up @@ -297,6 +301,8 @@ export const RichTextEditorMixin = (superClass) =>
this.__patchFirefoxFocus();
}

this.__setDirection(this.__dir);

const editorContent = editor.querySelector('.ql-editor');

editorContent.setAttribute('role', 'textbox');
Expand Down
21 changes: 21 additions & 0 deletions packages/rich-text-editor/test/basic.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,27 @@ describe('rich text editor', () => {
});
});

describe('RTL set initially', () => {
beforeEach(async () => {
rte = fixtureSync('<vaadin-rich-text-editor dir="rtl"></vaadin-rich-text-editor>');
await nextRender();
editor = rte._editor;
});

['center', 'left'].forEach((align) => {
it(`should apply ${align} alignment when clicking the "toolbar-button-align-${align}" part in RTL`, () => {
btn = getButton(`align-${align}`);

btn.click();
expect(editor.getFormat(0).align).to.be.equal(align);

btn = getButton('align-right');
btn.click();
expect(editor.getFormat(0).align).to.be.not.ok;
});
});
});

it('should clear formatting when clicking the "clean-button" part', () => {
editor.format('bold', true);
editor.format('underline', true);
Expand Down

0 comments on commit c94de89

Please sign in to comment.