FIX: Translated button title didn't work (#11872)

Follow-up to 6f13d2b039
This commit is contained in:
Gerhard Schlager 2021-01-28 08:32:02 +01:00 committed by GitHub
parent 9ae067164d
commit 5a6baa7c46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 3 deletions

View File

@ -31,9 +31,13 @@ export const ButtonClass = {
buildAttributes() {
const attrs = this.attrs;
const attributes = {};
let title = attrs.translatedTitle;
if (attrs.title) {
const title = I18n.t(attrs.title, attrs.titleOptions);
if (!title && attrs.title) {
title = I18n.t(attrs.title, attrs.titleOptions);
}
if (title) {
attributes["aria-label"] = title;
attributes.title = title;
}

View File

@ -53,7 +53,7 @@ export default createWidget("post-edits-indicator", {
return this.attach("flat-button", {
icon,
title,
translatedTitle: title,
className,
action: "onPostEditsIndicatorClick",
translatedLabel: attrs.version > 1 ? attrs.version - 1 : "",

View File

@ -82,4 +82,17 @@ discourseModule("Integration | Component | Widget | button", function (hooks) {
assert.equal(query("button span.d-button-label").innerText, "foo bar");
},
});
componentTest("translatedTitle", {
template: '{{mount-widget widget="button" args=args}}',
beforeEach() {
this.set("args", { label: "topic.create", translatedTitle: "foo bar" });
},
test(assert) {
assert.equal(query("button").title, "foo bar");
assert.equal(query("button").ariaLabel, "foo bar");
},
});
});