Input takes up whole width #6606
|
Hi, with this code I'd expect all the widgets to show: from textual.app import App, ComposeResult
from textual.containers import Horizontal, HorizontalGroup
from textual.widgets import Button, Input, Select, Label
class Sample(App):
def compose(self) -> ComposeResult:
with Horizontal(): # same with HorizontalGroup
yield Select.from_values(["foo", "bar"]).focus()
yield Input(placeholder="placeholder")
yield Button("Button")
with Horizontal(): # same with HorizontalGroup
yield Select.from_values(["foo", "bar"]).focus()
yield Button("Button")
if __name__ == "__main__":
sample = Sample()
sample.run()I guess Is this expected behavior? If so, what CSS could I apply, so that the Thank you! 🙏 |
Replies: 1 comment
|
Yeah, this is expected, and it comes down to Give Input the same class Sample(App):
CSS = """
Input { width: 1fr; }
"""Now Select, Input, and Button all share the row, and the Button keeps its 16-cell On auto-sizing Select to its content: there's no content-based width for it out of the box, so set an explicit |
Yeah, this is expected, and it comes down to
width. Input's default CSS iswidth: 100%, so inside aHorizontalit grabs the entire row and leaves nothing for the Button. Select is different: its default iswidth: 1fr, which is why it shares space and the Button survives in your second row (where there's no Input competing for the whole width).Give Input the same
1frtreatment and everything flexes together:Now Select, Input, and Button all share the row, and the Button keeps its 16-cell
min-width.On auto-sizing Select to its content: there's no content-based width for it out of the box, so set an explicit
widthor leave…