A platform for community discussion. Free, open, simple.
FIX: Tag-drop not highlighting the currently selected tag (visual-only) (#38492)
Natalie Tay56d219f9c415
diff --git a/frontend/discourse/select-kit/components/tag-drop.js b/frontend/discourse/select-kit/components/tag-drop.jsindex 7557b2836f1..fa9fa3997f8 100644--- a/frontend/discourse/select-kit/components/tag-drop.js+++ b/frontend/discourse/select-kit/components/tag-drop.js@@ -39,7 +39,7 @@ const MORE_TAGS_COLLECTION = "MORE_TAGS_COLLECTION";export default class TagDrop extends ComboBoxComponent {@service tagUtils;- @readOnly("tag.name") value;+ @readOnly("tag.id") value;@setting("max_tag_search_results") maxTagSearchResults;@setting("tags_sort_alphabetically") sortTagsAlphabetically;@@ -75,7 +75,7 @@ export default class TagDrop extends ComboBoxComponent {}modifyNoSelection() {- if (this.value === NONE_TAG) {+ if (this.tag?.name === NONE_TAG) {return this.defaultItem(NO_TAG_ID, i18n("tagging.selector_no_tags"));} else {return this.defaultItem(ALL_TAGS_ID, i18n("tagging.selector_tags"));@@ -83,7 +83,7 @@ export default class TagDrop extends ComboBoxComponent {}modifySelection(content) {- if (this.value === NONE_TAG) {+ if (this.tag?.name === NONE_TAG) {return this.defaultItem(NO_TAG_ID, i18n("tagging.selector_no_tags"));}@@ -94,9 +94,9 @@ export default class TagDrop extends ComboBoxComponent {return content;}- @computed("value")+ @computed("tag.slug")get tagClass() {- return this.value ? `tag-${this.value}` : "tag_all";+ return this.tag?.slug ? `tag-${this.tag.slug}` : "tag_all";}modifyComponentForRow() {diff --git a/spec/system/page_objects/components/select_kit.rb b/spec/system/page_objects/components/select_kit.rbindex 2ccd5d2776c..34f9b467f79 100644--- a/spec/system/page_objects/components/select_kit.rb+++ b/spec/system/page_objects/components/select_kit.rb@@ -134,6 +134,14 @@ module PageObjectsexpanded_component.all(".selected-choice").each(&:click)end+ def has_selected_row_name?(name)+ expanded_component.has_css?(".select-kit-row.is-selected[data-name='#{name}']")+ end++ def has_no_selected_row?+ expanded_component.has_no_css?(".select-kit-row.is-selected")+ end+def option_namesexpanded_component.all(".select-kit-row").map { |row| row["data-name"] }enddiff --git a/spec/system/tags/tags_spec.rb b/spec/system/tags/tags_spec.rbindex ec33f6a2ff2..1d8f8c84399 100644--- a/spec/system/tags/tags_spec.rb+++ b/spec/system/tags/tags_spec.rb@@ -149,6 +149,56 @@ describe "Tags", type: :system doexpect(discovery.topic_list).to have_topic(topic_with_one_tag)end+ it "highlights the selected tag in the tag-drop dropdown" do+ ditto = Fabricate(:tag, name: "ditto")+ bulbasaur = Fabricate(:tag, name: "bulbasaur")+ sprigatito = Fabricate(:tag, name: "sprigatito")+ tag_category = Fabricate(:category)++ [ditto, bulbasaur, sprigatito].each do |tag|+ Fabricate(:topic, category: tag_category, tags: [tag]).tap do |t|+ Fabricate(:post, topic: t)+ end+ end+ CategoryTagStat.update_topic_counts++ sign_in(user_tl1)++ # visit tag page, tag-drop should highlight the active tag+ tag_page.visit_tag(ditto)+ discovery.tag_drop.expand+ expect(discovery.tag_drop).to have_selected_row_name("ditto")++ # search for the active tag, result should still be highlighted+ discovery.tag_drop.search(ditto.name)+ expect(discovery.tag_drop).to have_selected_row_name("ditto")++ # search for a different tag, no row should be highlighted+ discovery.tag_drop.search(bulbasaur.name)+ expect(discovery.tag_drop).to have_no_selected_row++ # select a different tag, navigate, verify new selection+ discovery.tag_drop.select_row_by_name("bulbasaur")+ expect(page).to have_current_path("/tag/#{bulbasaur.slug}/#{bulbasaur.id}")++ discovery.tag_drop.expand+ expect(discovery.tag_drop).to have_selected_row_name("bulbasaur")++ # "remove filter" navigates back with no selected tag+ discovery.tag_drop.select_row_by_value("all-tags")+ expect(page).to have_current_path("/")++ discovery.tag_drop.expand+ expect(discovery.tag_drop).to have_no_selected_row++ # "no tags" filter shows untagged topics+ discovery.tag_drop.select_row_by_value("no-tags")+ expect(page).to have_current_path("/tag/none")++ discovery.tag_drop.expand+ expect(discovery.tag_drop).to have_no_selected_row+ end+it "filters to untagged topics when selecting 'no tags' from tag drop" dosign_in(user_tl1)visit "/latest"