New Topic button hidden text

AI-generated summary

Juan_Manuel_Barreto asked for help preserving the “New Topic” text on the mobile view of the New Post button, which currently hides the label for responsiveness. The HTML differs between desktop (shows text) and mobile (hides text, showing only an icon). awesomerobot responded that there was no built-in way to restore the text on mobile — so they added one via a GitHub PR. The fix allows admins or theme developers to override the default behavior using a JS snippet in a theme’s initializer or via the admin panel’s theme editor. The provided code uses api.registerValueTransformer to force the label to appear on both desktop and mobile. A screenshot shows the resulting button with the label restored on mobile. This change will be available in the next Discourse update.

Hi! I have been trying to make a style change to the New Post button, but I haven’t been able to figure out a way to do this, and wanted to know if someone could help with ideas on how to solve this.

This is the way the New Topic button looks like on the Desktop and Mobile view:

The responsiveness hides the New Topic text from the button, I would like to preserve this text on the mobile view too, how could I achieve this?

Additionally, these are the html elements that appear on each view:

ELEMENT IN MOBILE:

<button class="btn no-text btn-icon btn-default" id="create-topic" type="button">
<svg class="fa d-icon d-icon-far-pen-to-square svg-icon svg-string" xmlns="http://www.w3.org/2000/svg"><use href="#far-pen-to-square"></use></svg>      <span aria-hidden="true">
          ​
        </span>
    </button>

ELEMENT IN DESKTOP

<button class="btn btn-icon-text btn-default" id="create-topic" type="button">
<svg class="fa d-icon d-icon-far-pen-to-square svg-icon svg-string" xmlns="http://www.w3.org/2000/svg"><use href="#far-pen-to-square"></use></svg>      <span class="d-button-label">New Post<!----></span>
    </button>

Any help will be highly appreciated!

We didn’t actually have a great way to get this text back on mobile, so I just added one: DEV: add create-topic-label value transformer by awesomerobot · Pull Request #32621 · discourse/discourse · GitHub — you’ll get this the next time Discourse is updated..

This change will allow you to override our default behavior in an initializer file in a remote theme, or via the admin panel within the admin/customize/themes code editor’s JS tab:

import { apiInitializer } from "discourse/lib/api";

export default apiInitializer((api) => {

  api.registerValueTransformer("create-topic-label", ({ value, context }) => {
    return context.defaultKey;
  });

});

:backhand_index_pointing_up: this will override our default mobile/desktop switch with the label, so it will appear in both places: