Skip to content

Commit ca54b56

Browse files
authored
feat: add indent and outdent toolbar buttons and i18n strings (#9971)
1 parent a1b0ddc commit ca54b56

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+160
-47
lines changed

packages/rich-text-editor/src/styles/vaadin-rich-text-editor-base-icons.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/rich-text-editor/src/styles/vaadin-rich-text-editor-base-styles.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,14 @@ const toolbar = css`
515515
mask-image: var(--_vaadin-icon-list-bullet);
516516
}
517517
518+
[part~='toolbar-button-outdent']::before {
519+
mask-image: var(--_vaadin-icon-outdent);
520+
}
521+
522+
[part~='toolbar-button-indent']::before {
523+
mask-image: var(--_vaadin-icon-indent);
524+
}
525+
518526
[part~='toolbar-button-align-left']::before {
519527
mask-image: var(--_vaadin-icon-align-left);
520528
}

packages/rich-text-editor/src/vaadin-rich-text-editor-mixin.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export interface RichTextEditorI18n {
2727
superscript?: string;
2828
listOrdered?: string;
2929
listBullet?: string;
30+
outdent?: string;
31+
indent?: string;
3032
alignLeft?: string;
3133
alignCenter?: string;
3234
alignRight?: string;

packages/rich-text-editor/src/vaadin-rich-text-editor-mixin.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ const DEFAULT_I18N = {
7777
superscript: 'superscript',
7878
listOrdered: 'list ordered',
7979
listBullet: 'list bullet',
80+
outdent: 'outdent',
81+
indent: 'indent',
8082
alignLeft: 'align left',
8183
alignCenter: 'align center',
8284
alignRight: 'align right',

packages/rich-text-editor/src/vaadin-rich-text-editor.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export interface RichTextEditorEventMap extends HTMLElementEventMap, RichTextEdi
6060
* `toolbar-group-style` | The group for style controls
6161
* `toolbar-group-glyph-transformation` | The group for glyph transformation controls
6262
* `toolbar-group-list` | The group for list controls
63+
* `toolbar-group-indent` | The group for indentation controls
6364
* `toolbar-group-alignment` | The group for alignment controls
6465
* `toolbar-group-rich-text` | The group for rich text controls
6566
* `toolbar-group-block` | The group for preformatted block controls
@@ -81,6 +82,8 @@ export interface RichTextEditorEventMap extends HTMLElementEventMap, RichTextEdi
8182
* `toolbar-button-superscript` | The "superscript" button
8283
* `toolbar-button-list-ordered` | The "ordered list" button
8384
* `toolbar-button-list-bullet` | The "bullet list" button
85+
* `toolbar-button-outdent` | The "decrease indentation" button
86+
* `toolbar-button-indent` | The "increase indentation" button
8487
* `toolbar-button-align-left` | The "left align" button
8588
* `toolbar-button-align-center` | The "center align" button
8689
* `toolbar-button-align-right` | The "right align" button

packages/rich-text-editor/src/vaadin-rich-text-editor.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import { RichTextEditorMixin } from './vaadin-rich-text-editor-mixin.js';
5858
* `toolbar-group-style` | The group for style controls
5959
* `toolbar-group-glyph-transformation` | The group for glyph transformation controls
6060
* `toolbar-group-list` | The group for list controls
61+
* `toolbar-group-indent` | The group for indentation controls
6162
* `toolbar-group-alignment` | The group for alignment controls
6263
* `toolbar-group-rich-text` | The group for rich text controls
6364
* `toolbar-group-block` | The group for preformatted block controls
@@ -79,6 +80,8 @@ import { RichTextEditorMixin } from './vaadin-rich-text-editor-mixin.js';
7980
* `toolbar-button-superscript` | The "superscript" button
8081
* `toolbar-button-list-ordered` | The "ordered list" button
8182
* `toolbar-button-list-bullet` | The "bullet list" button
83+
* `toolbar-button-outdent` | The "decrease indentation" button
84+
* `toolbar-button-indent` | The "increase indentation" button
8285
* `toolbar-button-align-left` | The "left align" button
8386
* `toolbar-button-align-center` | The "center align" button
8487
* `toolbar-button-align-right` | The "right align" button
@@ -259,6 +262,27 @@ class RichTextEditor extends RichTextEditorMixin(
259262
></button>
260263
</span>
261264
265+
<span part="toolbar-group toolbar-group-indent">
266+
<!-- Decrease -->
267+
<button
268+
id="btn-outdent"
269+
type="button"
270+
class="ql-indent"
271+
value="-1"
272+
part="toolbar-button toolbar-button-outdent"
273+
aria-label="${this.__effectiveI18n.outdent}"
274+
></button>
275+
<!-- Increase -->
276+
<button
277+
id="btn-indent"
278+
type="button"
279+
class="ql-indent"
280+
value="+1"
281+
part="toolbar-button toolbar-button-indent"
282+
aria-label="${this.__effectiveI18n.indent}"
283+
></button>
284+
</span>
285+
262286
<span part="toolbar-group toolbar-group-alignment">
263287
<!-- Align buttons -->
264288
<button

packages/rich-text-editor/test/a11y.test.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -263,27 +263,35 @@ describe('accessibility', () => {
263263
});
264264

265265
describe('indent', () => {
266+
let indent;
267+
266268
beforeEach(async () => {
267269
rte = fixtureSync('<vaadin-rich-text-editor></vaadin-rich-text-editor>');
268270
await nextRender();
269271
editor = rte._editor;
270-
buttons = Array.from(rte.shadowRoot.querySelectorAll(`[part=toolbar] button`));
272+
indent = rte.shadowRoot.querySelector('#btn-indent');
271273
content = rte.shadowRoot.querySelector('[contenteditable]');
272274
});
273275

274-
it('should represent indentation correctly', () => {
275-
rte.value = JSON.stringify([
276-
{ insert: 'Indent 1\n', attributes: { indent: 1 } },
277-
{ insert: 'Indent 2\n', attributes: { indent: 2 } },
278-
]);
279-
expect(content.innerHTML).to.equal('<p class="ql-indent-1">Indent 1</p><p class="ql-indent-2">Indent 2</p>');
280-
});
276+
it('should represent indentation correctly', async () => {
277+
editor.focus();
278+
indent.click();
281279

282-
it('should convert ql-indent-* classes to tabs in htmlValue', () => {
283-
rte.value = JSON.stringify([
284-
{ insert: 'Indent 1\n', attributes: { indent: 1 } },
285-
{ insert: 'Indent 2\n', attributes: { indent: 2 } },
286-
]);
280+
await sendKeys({ type: 'Indent 1' });
281+
await sendKeys({ press: 'Enter' });
282+
await sendKeys({ press: 'Tab' });
283+
await sendKeys({ type: 'Indent 2' });
284+
flushValueDebouncer();
285+
286+
expect(rte.value).to.equal(
287+
JSON.stringify([
288+
{ insert: 'Indent 1' },
289+
{ attributes: { indent: 1 }, insert: '\n' },
290+
{ insert: 'Indent 2' },
291+
{ attributes: { indent: 2 }, insert: '\n' },
292+
]),
293+
);
294+
expect(content.innerHTML).to.equal('<p class="ql-indent-1">Indent 1</p><p class="ql-indent-2">Indent 2</p>');
287295
expect(rte.htmlValue).to.equal('<p>\tIndent 1</p><p>\t\tIndent 2</p>');
288296
});
289297

packages/rich-text-editor/test/dom/__snapshots__/rich-text-editor.test.snap.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,30 @@ snapshots["vaadin-rich-text-editor shadow"] =
598598
>
599599
</button>
600600
</span>
601+
<span part="toolbar-group toolbar-group-indent">
602+
<button
603+
aria-label="outdent"
604+
aria-pressed="false"
605+
class="ql-indent"
606+
id="btn-outdent"
607+
part="toolbar-button toolbar-button-outdent"
608+
tabindex="-1"
609+
type="button"
610+
value="-1"
611+
>
612+
</button>
613+
<button
614+
aria-label="indent"
615+
aria-pressed="false"
616+
class="ql-indent"
617+
id="btn-indent"
618+
part="toolbar-button toolbar-button-indent"
619+
tabindex="-1"
620+
type="button"
621+
value="+1"
622+
>
623+
</button>
624+
</span>
601625
<span part="toolbar-group toolbar-group-alignment">
602626
<button
603627
aria-label="align left"

packages/rich-text-editor/test/toolbar.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,28 @@ describe('toolbar controls', () => {
9595
});
9696
});
9797

98+
it('should increase indentation when clicking the "toolbar-button-indent" part', () => {
99+
btn = getButton('indent');
100+
101+
btn.click();
102+
expect(editor.getFormat(0).indent).to.be.equal(1);
103+
104+
btn.click();
105+
expect(editor.getFormat(0).indent).to.be.equal(2);
106+
});
107+
108+
it('should decrease indentation when clicking the "toolbar-button-outdent" part', () => {
109+
rte.value = JSON.stringify([{ insert: 'Indent 2\n', attributes: { indent: 2 } }]);
110+
111+
btn = getButton('outdent');
112+
113+
btn.click();
114+
expect(editor.getFormat(0).indent).to.be.equal(1);
115+
116+
btn.click();
117+
expect(editor.getFormat(0).indent).to.be.not.ok;
118+
});
119+
98120
[1, 2].forEach((level) => {
99121
it(`should create <h${level}> header when clicking the "toolbar-button-h${level}" part`, () => {
100122
btn = getButton(`h${level}`);
310 Bytes

0 commit comments

Comments
 (0)