Avaiga / taipy

Turns Data and AI algorithms into production-ready web applications in no time.
https://www.taipy.io
Apache License 2.0
15.3k stars 1.86k forks source link

[πŸ› BUG] Stylekit is not applied for text with mode="md" #1553

Closed FlorianJacta closed 2 weeks ago

FlorianJacta commented 3 months ago

What went wrong? πŸ€”

Some styles in the Stylekit (through the class_name) are not applied when mode="md" is set for text visual element. This prevents the user from changing the text element like he wants.

The issue comes from a user: https://github.com/Avaiga/taipy/discussions/1547

Expected Behavior

The class_name/stylekit should be applied for all styles even with mode="md".

Steps to Reproduce Issue

Style don't work:

import taipy.gui.builder as tgb 
from taipy import Gui 

x = {"a": {"b": {"": 1}}}

with tgb.Page() as page:
    with tgb.layout('5*1', gap='2.0rem'):
        card_style = 'card pb0 m0'
        heading_style = 'text-right h5 color-primary pb0'
        number_style = 'text-right h1 pb0'
        with tgb.part(card_style):
            tgb.text("**Headline**", class_name=heading_style, mode="md")
            tgb.text("{x['a']['b']['']}", format='%.0f', class_name=number_style, "mode="md")

Gui(page).run()

image

Works (but without the Markdown format:

import taipy.gui.builder as tgb 
from taipy import Gui 

x = {"a": {"b": {"": 1}}}

with tgb.Page() as page:
    with tgb.layout('5*1', gap='2.0rem'):
        card_style = 'card pb0 m0'
        heading_style = 'text-right h5 color-primary pb0'
        number_style = 'text-right h1 pb0'
        with tgb.part(card_style):
            tgb.text("**Headline**", class_name=heading_style)
            tgb.text("{x['a']['b']['']}", format='%.0f', class_name=number_style)

Gui(page).run()

image

Solution Proposed

This seems to come from a

tag surrounding the text and not being a span like the normal visual element.

Version of Taipy

3.1.1 / Develop

Acceptance Criteria

Code of Conduct

FredLL-Avaiga commented 3 months ago

It seems legit that HTML elements are added when in markdown mode (that's the point of markdown: generate HTML tags) and that one would have to set styles differently ...

Satoshi-Sh commented 4 weeks ago

Can I take this issue?

jrobinAV commented 4 weeks ago

Sure

Satoshi-Sh commented 3 weeks ago

I have a question. tgb.text with md mode is related to the Field.tsx component using reac-markdown?

Screenshot from 2024-10-08 13-11-02

I updated this code but the behavior doesn't change. Let me know if I'm missing something. Thanks.

@FredLL-Avaiga

FredLL-Avaiga commented 3 weeks ago

Yes it is Did you rebuild the frontend bundle?

Satoshi-Sh commented 3 weeks ago

Yes, I rebuilt it. I will try again.

UPDATE I found an eslint error. That's why I couldn't see the change.

Satoshi-Sh commented 2 weeks ago

I tried to fix this issue but there seems no reasonable solution after talking with Fred. I closed my PR. You may change the state of the issue. @jrobinAV Thanks

FredLL-Avaiga commented 2 weeks ago

won't fix: Stylekit classes usually cannot be applied to text in mode "md" because the markdown creates new tags inside the div that receives the stylekit classes.for example any simple text in md mode will be rendered as <div data-comment="from text comp" class="taipy-text stylekit classes"><p>{text value}</p></div> Some stylekit classes might have an effect but I would recommend to not use them and use direct styling of the component via CSS.