Just a note to share that this was worked on but then was found to be a big change, so closed. It’s a great idea but it’s not certain that it will be picked up by the team anytime soon unfortunately.
main
← add-tag-groups-for-tag
opened 07:55AM - 17 Jul 24 UTC
## Overview
This commit adds the `data-tag-groups` attribute to tags, making … it easier to use CSS selectors to batch select tags belonging to certain tag groups.
An example:
```html
<a href="/tag/hidden" data-tag-name="hidden" data-tag-groups="Hidden Tag Group, non-hidden tags" class="discourse-tag box">hidden</a>
```
Related meta topic: https://meta.discourse.org/t/add-a-data-tag-group-attribute-for-tags/234410
## Detailed changes
Add data-groups to these...
- [ ] Tags for topics
- [x] The effect has been shown
- [ ] Tests already written
- [ ] Confirms that there are no performance issues
- [ ] TagChooser at the top of TopicList
- [x] The effect has been shown
- [x] Tests already written
- [ ] Confirms that there are no performance issues
- [ ] Tags on the sidebar
- [x] The effect has been shown
- [ ] Tests already written
- [ ] Confirms that there are no performance issues
- [ ] Tags on the `/tags` page
- [x] The effect has been shown
- [ ] Tests already written
- [ ] Confirms that there are no performance issues
- [ ] Search bar tags
- [x] The effect has been shown
- [ ] Tests already written
- [ ] Confirms that there are no performance issues
- [ ] Composer tags chooser
- [x] The effect has been shown
- [ ] Tests already written
- [ ] Confirms that there are no performance issues
- [ ] ~~Tags in the post body~~ Maybe next PR
## DEV Improvements
Partially rewrote `defaultRenderTag` for better scalability and clarity:
The new `defaultRenderTag` reserves an interface for theme components to avoid the need for components to completely rewrite `defaultRenderTag` to provide custom tag renderer.
For example, you can now replace the tagRenderer like this:
```javascript
api.replaceTagRenderer((tag, params) => {
return defaultRenderTag(tag, params, {
extraClass: "custom-tag-class",
contentFn(old) {
return `${iconHTML("tag")}${old}`;
},
});
});
```
This has a significant benefit for discourse tag icons. Since the [old way of code](https://github.com/discourse/discourse-tag-icons/blob/main/javascripts/discourse/initializers/tag-icons.js#L9-L84) the changes made by this PR will be completely overwritten by discourse tag icons, and the theme component must be updated accordingly.
After applying the new interface, it can automatically synchronize changes with the `defaultRendererTag` in core.
2 Likes