Skip to content

overlay style removes the neighboring margin #5670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TomJGooding opened this issue Mar 24, 2025 · 4 comments
Closed

overlay style removes the neighboring margin #5670

TomJGooding opened this issue Mar 24, 2025 · 4 comments

Comments

@TomJGooding
Copy link
Contributor

The overlay style (added in Textual v0.24.0) is still undocumented, so I'm not sure if this is a bug or I've misunderstood how the overlay should work.

Here's a minimal example. After typing in the input to show the overlay, the top margin of the button below will disappear:

from textual.app import App, ComposeResult
from textual.widgets import Button, Input, Static


class MyOverlay(Static):
    DEFAULT_CSS = """
    MyOverlay {
        display: none;
        overlay: screen;
        background: $error;
    }
    """


class ExampleApp(App):
    CSS = """
    Button {
        margin: 2;
    }
    """

    def compose(self) -> ComposeResult:
        yield Input(placeholder="Type to show the overlay...")
        yield MyOverlay("This overlay removes the margin?")
        yield Button("Submit", variant="success")

    def on_input_changed(self, event: Input.Changed) -> None:
        self.query_one(MyOverlay).display = bool(event.value)


if __name__ == "__main__":
    app = ExampleApp()
    app.run()
Copy link

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

@TomJGooding TomJGooding changed the title overlay style removes the margin overlay style removes the neighboring margin Mar 24, 2025
@willmcgugan
Copy link
Collaborator

This is because the margin overlaps with the previous widget in the DOM. When you make the overlay visible, it makes the previous widget the overlay, rather than the Input.

It's possible we can be a little smarter than this re margins. In the meantime, you could put your Input + Overlay inside a container. That should give the effect you are looking for,

@willmcgugan
Copy link
Collaborator

It doesn't look easy to handle this transparently. Putting the Input and Overlay in a VerticalGroup seems like a workable solution. Closing as I think this is good enough for now.

Copy link

github-actions bot commented Apr 9, 2025

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants