Incorrect width is calculated for Labels with style tags (Rich Text)

I added Text Style Sheet with bold style: <style=“bold”>text :arrow_right: text
But when I’m using it in Label, its width is incorrectly calculated, looks like instead of result text width, original width of text with tags is used, although excluding closing tag.
You can see the issue in the screenshot, 1st Label has incorrect width (I marked space that shouldn’t be there), 2nd Label has the same text but with disabled Rich Text, 3rd is just bold text () without style.


index.uxml

<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
    <Style src="project://database/Assets/NewUSSFile.uss?fileID=7433441132597879392&guid=e80ab3813b9fd9240a67b2e1a7b3a693&type=3#NewUSSFile" />
    <ui:VisualElement class="row">
        <ui:Label text="<style="bold">bold style text</style>" />
        <ui:Label text="Label" />
    </ui:VisualElement>
    <ui:VisualElement class="row">
        <ui:Label text="<style="bold">bold style text</style>" enable-rich-text="false" />
        <ui:Label text="Label" />
    </ui:VisualElement>
    <ui:VisualElement class="row">
        <ui:Label text="<b>b text</b>" />
        <ui:Label text="Label" />
    </ui:VisualElement>
</ui:UXML>

style.uss

.row {
    justify-content: space-between;
    flex-direction: row;
}

Label {
    background-color: white;
}

Hi @RunninglVlan !

Thanks a lot for bringing this up, could you log a bug through the Unity Bug Reporter? (It’s located under the Help/Report a bug… menu item).

Sorry for the inconvenience, we’ll try to look into it shortly.

1 Like

Reported: CASE IN-9604
Forgot to tell that I was using Unity 2022.2.0a18

1 Like