UX: Prevent category-drop topic count from wrapping to new line (#8943)

This commit is contained in:
Penar Musaraj 2020-02-12 14:34:16 -05:00 committed by GitHub
parent c36ae17260
commit efa9ba4975
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 4 deletions

View File

@ -151,6 +151,13 @@ function defaultCategoryLinkRenderer(category, opts) {
} }
html += "</span>"; html += "</span>";
if (opts.topicCount) {
html += `<span class="topic-count" aria-label="${I18n.t(
"category_row.topic_count",
{ count: opts.topicCount }
)}">&times; ${opts.topicCount}</span>`;
}
if (href) { if (href) {
href = ` href="${href}" `; href = ` href="${href}" `;
} }

View File

@ -53,7 +53,8 @@ export default SelectKitRowComponent.extend({
link: this.categoryLink, link: this.categoryLink,
allowUncategorized: allowUncategorized:
this.allowUncategorizedTopics || this.allowUncategorized, this.allowUncategorizedTopics || this.allowUncategorized,
hideParent: !!this.parentCategory hideParent: !!this.parentCategory,
topicCount: this.topicCount
}).htmlSafe(); }).htmlSafe();
}), }),

View File

@ -6,9 +6,6 @@
{{/unless}} {{/unless}}
{{/if}} {{/if}}
{{badgeForCategory}} {{badgeForCategory}}
<span class="topic-count" aria-label={{i18n "category_row.topic_count" count=topicCount}}>
&times; {{topicCount}}
</span>
</div> </div>
{{#if shouldDisplayDescription}} {{#if shouldDisplayDescription}}

View File

@ -46,6 +46,21 @@ QUnit.test("undefined color", assert => {
); );
}); });
QUnit.test("topic count", assert => {
const store = createStore();
const category = store.createRecord("category", { name: "hello", id: 123 });
assert.equal(
categoryBadgeHTML(category).indexOf("topic-count"),
-1,
"it does not include topic count by default"
);
assert.ok(
categoryBadgeHTML(category, { topicCount: 20 }).indexOf("topic-count") > 20,
"is included when specified"
);
});
QUnit.test("allowUncategorized", assert => { QUnit.test("allowUncategorized", assert => {
const store = createStore(); const store = createStore();
const uncategorized = store.createRecord("category", { const uncategorized = store.createRecord("category", {