DEV: emoji helper: add the ability to set custom title (#17517)

This commit is contained in:
Andrei Prigorshnev 2022-07-18 21:51:19 +04:00 committed by GitHub
parent 80bda4a9db
commit 48e2caf7b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -11,4 +11,13 @@ module("Integration | Helper | emoji", function (hooks) {
await render(hbs`{{emoji "tada"}}`);
assert.ok(exists(`.emoji[title="tada"]`));
});
test("it renders custom title", async function (assert) {
const title = "custom title";
this.set("title", title);
await render(hbs`{{emoji "tada" title=this.title}}`);
assert.ok(exists(`.emoji[title="${title}"]`));
});
});

View File

@ -92,12 +92,13 @@ export function performEmojiUnescape(string, opts) {
(isEmoticon || hasEndingColon || isUnicodeEmoticon) &&
isReplacableInlineEmoji(string, index, opts.inlineEmoji);
const title = opts.title ?? emojiVal;
return url && isReplacable
? `<img width="20" height="20" src='${url}' ${
opts.skipTitle ? "" : `title='${emojiVal}'`
opts.skipTitle ? "" : `title='${title}'`
} ${
opts.lazy ? "loading='lazy' " : ""
}alt='${emojiVal}' class='${classes}'>`
}alt='${title}' class='${classes}'>`
: m;
};