Skip to content

Build your personal knowledge base with Trilium Notes

client/text editor/multicolumn layout: mention the column number in the widget's toolbar

Adorian Doran285646d78946
diff --git a/packages/ckeditor5/src/plugins/multicolumn/multicolumn_ui.spec.ts b/packages/ckeditor5/src/plugins/multicolumn/multicolumn_ui.spec.ts
index 940c9c6fc8..de7ddeba9c 100644
--- a/packages/ckeditor5/src/plugins/multicolumn/multicolumn_ui.spec.ts
+++ b/packages/ckeditor5/src/plugins/multicolumn/multicolumn_ui.spec.ts
@@ -183,6 +183,18 @@ describe("MulticolumnUI", () => {
return [...row.tiles];
}
+ /** The visible text, the tooltip and the accessible name of the dropdown's button. */
+ function labelsOf(dropdown: DropdownView) {
+ const button = dropdown.buttonView.element;
+ expect(button?.classList.contains("ck-button_with-text")).toBe(true);
+ expect(button?.hasAttribute("aria-labelledby")).toBe(false);
+ return [
+ button?.querySelector(".ck-button__label")?.textContent,
+ dropdown.buttonView.tooltip,
+ button?.getAttribute("aria-label")
+ ];
+ }
+
it("shows a figure of every layout, with the current one on and focused", () => {
setModelData(editor.model, layout("1-3", paragraph("A[]"), paragraph("B")));
const dropdown = createDropdown();
@@ -203,7 +215,8 @@ describe("MulticolumnUI", () => {
expect(tiles.filter(tile => tile.isOn).map(tile => tile.label))
.toEqual(["2 columns (25%-75%)"]);
expect(document.activeElement).toBe(tiles[1].element);
- expect(dropdown.buttonView.label).toBe("Column layout");
+ expect(labelsOf(dropdown))
+ .toEqual(["2 columns", "Column layout", "2 columns, Column layout"]);
expect(dropdown.buttonView.icon).toBe(createLayoutFigure("1-3", 20));
expect(dropdown.isEnabled).toBe(true);
});
@@ -218,6 +231,8 @@ describe("MulticolumnUI", () => {
expect(getModelData(editor.model, { withoutSelection: true }))
.toBe(layout("1-2-1", paragraph("A"), paragraph("B"), paragraph("")));
expect(dropdown.buttonView.icon).toBe(createLayoutFigure("1-2-1", 20));
+ expect(labelsOf(dropdown))
+ .toEqual(["3 columns", "Column layout", "3 columns, Column layout"]);
expect(dropdown.isOpen).toBe(false);
expect(focus).toHaveBeenCalled();
});
@@ -228,6 +243,8 @@ describe("MulticolumnUI", () => {
expect(dropdown.isEnabled).toBe(false);
expect(dropdown.buttonView.icon).toBe(multicolumnIcon);
+ expect(labelsOf(dropdown))
+ .toEqual(["Column layout", "Column layout", "Column layout"]);
expect(tilesOf(dropdown).some(tile => tile.isOn)).toBe(false);
});
});
@@ -259,7 +276,7 @@ describe("MulticolumnUI", () => {
const items = [...toolbar.items] as (DropdownView | ButtonView)[];
const buttons = items.map(item => "buttonView" in item ? item.buttonView : item);
expect(buttons.map(button => [button.label, button.icon])).toEqual([
- ["Column layout", createLayoutFigure("1-3", 20)],
+ ["2 columns", createLayoutFigure("1-3", 20)],
["Remove layout", IconRemove]
]);
});
diff --git a/packages/ckeditor5/src/plugins/multicolumn/multicolumn_ui.ts b/packages/ckeditor5/src/plugins/multicolumn/multicolumn_ui.ts
index 5bf1f4ddfb..d8e6257f44 100644
--- a/packages/ckeditor5/src/plugins/multicolumn/multicolumn_ui.ts
+++ b/packages/ckeditor5/src/plugins/multicolumn/multicolumn_ui.ts
@@ -113,15 +113,26 @@ export default class MulticolumnUI extends Plugin {
return dropdown;
}
- /** A dropdown with a figure of every column layout, grouped by column count. */
+ /**
+ * A dropdown with a figure of every column layout, grouped by column count. Its button shows
+ * the figure and the column count of the current layout.
+ */
private createLayoutDropdown(locale: Locale) {
const editor = this.editor;
const label = editor.t("Column layout");
const command = editor.commands.get("columnLayout") as ColumnLayoutCommand;
+ const getCountLabel = (ratios: string | undefined) =>
+ ratios && editor.t("%0 columns", getColumnCount(ratios));
const dropdown = createDropdown(locale);
- dropdown.buttonView.set({ label, tooltip: true });
+ dropdown.buttonView.set({ ariaLabelledBy: undefined, withText: true, tooltip: label });
dropdown.buttonView.bind("icon").to(command, "value", value =>
value ? createLayoutFigure(value, BUTTON_ICON_SIZE) : multicolumnIcon);
+ dropdown.buttonView.bind("label").to(command, "value", value =>
+ getCountLabel(value) || label);
+ dropdown.buttonView.bind("ariaLabel").to(command, "value", value => {
+ const countLabel = getCountLabel(value);
+ return countLabel ? `${countLabel}, ${label}` : label;
+ });
dropdown.bind("isEnabled").to(command, "isEnabled");
const groups = new Map<number, ButtonView[]>();