mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Add support for condition option when adding toolbar buttons (#24370)
This commit is contained in:
parent
d589c4c47f
commit
00f7e58da4
@ -27,6 +27,7 @@
|
||||
<div class="d-editor-button-bar" role="toolbar">
|
||||
{{#each this.toolbar.groups as |group|}}
|
||||
{{#each group.buttons as |b|}}
|
||||
{{#if (b.condition this)}}
|
||||
{{#if b.popupMenu}}
|
||||
<ToolbarPopupMenuOptions
|
||||
@content={{this.popupMenuOptions}}
|
||||
@ -49,6 +50,7 @@
|
||||
class={{b.className}}
|
||||
/>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{/each}}
|
||||
{{/each}}
|
||||
</div>
|
||||
|
@ -170,12 +170,13 @@ class Toolbar {
|
||||
tabindex: button.tabindex || "-1",
|
||||
className: button.className || button.id,
|
||||
label: button.label,
|
||||
icon: button.label ? null : button.icon || button.id,
|
||||
icon: button.icon || button.id,
|
||||
action: button.action || ((a) => this.context.send("toolbarButton", a)),
|
||||
perform: button.perform || function () {},
|
||||
trimLeading: button.trimLeading,
|
||||
popupMenu: button.popupMenu || false,
|
||||
preventFocus: button.preventFocus || false,
|
||||
condition: button.condition || (() => true),
|
||||
};
|
||||
|
||||
if (button.sendAction) {
|
||||
|
@ -695,6 +695,33 @@ third line`
|
||||
);
|
||||
});
|
||||
|
||||
test("Toolbar buttons are only rendered when condition is met", async function (assert) {
|
||||
withPluginApi("0.1", (api) => {
|
||||
api.onToolbarCreate((toolbar) => {
|
||||
toolbar.addButton({
|
||||
id: "shown",
|
||||
group: "extras",
|
||||
icon: "far-smile",
|
||||
action: () => {},
|
||||
condition: () => true,
|
||||
});
|
||||
|
||||
toolbar.addButton({
|
||||
id: "not-shown",
|
||||
group: "extras",
|
||||
icon: "far-frown",
|
||||
action: () => {},
|
||||
condition: () => false,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
await render(hbs`<DEditor/>`);
|
||||
|
||||
assert.ok(exists(".d-editor-button-bar button.shown"));
|
||||
assert.notOk(exists(".d-editor-button-bar button.not-shown"));
|
||||
});
|
||||
|
||||
test("toolbar buttons tabindex", async function (assert) {
|
||||
await render(hbs`<DEditor />`);
|
||||
const buttons = queryAll(".d-editor-button-bar .btn");
|
||||
|
Loading…
Reference in New Issue
Block a user