Skip to content

tcss "text-align: left;" not working anymore for Buttons #5884

Open
@gpregger-ethz

Description

@gpregger-ethz

The bug

The TCSS property "text-align: left" on a button element causes the button's caption to be aligned to the center instead of to the left.
text-align: right, end and center work as expected, but left or start do the same as center.

MRE

# main.py
from textual.app import App
from textual.screen import Screen
from textual.widgets import Button

class Screen_Button(Screen):
    def compose(self):
        yield Button('Button1', id='btn_1', variant='primary')
        yield Button('Button2', id='btn_2', variant='success')
        yield Button('Button3', id='btn_3', variant='error')

class MRE(App):
    CSS_PATH = 'style.tcss'

    SCREENS = {
        'scr_mre' : Screen_Button
    }

    def on_mount(self) -> None:
        self.title = 'Button text-align MRE'
        self.push_screen('scr_mre')

if __name__ == '__main__':
    app = MRE()
    app.run()
/* style.tcss */
Button {
    text-align: right;
}

#btn_1 {
    text-align: left;
}

#btn_2 {
    text-align: center;
}

expected:

Image

actual:

Image

This worked as expected up to and including the 2.1.2 release and broke with the 3.0.0 release.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions