FIX: Make tagsHtml callback respect tagName option (#173)

Makes the assigned icon and label non-interactive in search results dropdown.
This commit is contained in:
Jarek Radosz 2021-07-20 12:37:33 +02:00 committed by GitHub
parent 09b7655206
commit 4e657b97df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 4 deletions

View File

@ -231,13 +231,16 @@ function initialize(api) {
api.addDiscoveryQueryParam("assigned", { replace: true, refreshModel: true });
api.addTagsHtmlCallback((topic) => {
api.addTagsHtmlCallback((topic, params) => {
const assignedTo = topic.get("assigned_to_user.username");
if (assignedTo) {
const assignedPath = topic.assignedToUserPath;
return `<a data-auto-route='true' class='assigned-to discourse-tag simple' href='${assignedPath}'>${iconHTML(
"user-plus"
)}${assignedTo}</a>`;
const tagName = params.tagName || "a";
const icon = iconHTML("user-plus");
const href =
tagName === "a" ? `href="${assignedPath}" data-auto-route="true"` : "";
return `<${tagName} class="assigned-to discourse-tag simple" ${href}>${icon}${assignedTo}</${tagName}>`;
}
});