beeware / beeware/toga

Display = NONE doesn't work like CSS

Open
#3,322 3 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
5.4k
Forks
827
Avg merge
9h 45m
Merged PRs (30d)
58

Description

### Describe the bug

As requested by HalfWhitt on discord, it seems that the display style doesn't work how it should according to css. https://developer.mozilla.org/en-US/docs/Web/CSS/display#none suggests that it should hide the element and not take up the space which currently does not happen.

### Steps to reproduce

```python
class testing(toga.App):
def startup(self):
main_box = toga.Box(style=Pack(direction=COLUMN))
hide_element_button = toga.Button("Toggle hide element", on_press=self.toggle_hide)
display_none_element_button = toga.Button("Toggle display None", on_press=self.toggle_display)
button_box = toga.Box(children=[hide_element_button, display_none_element_button])

self.testing_box = toga.Box(style=Pack(padding=5, background_color="red", height=100))

main_box.add(button_box,
toga.Box(style=Pack(padding=5, background_color="yellow", height=100 )),
self.testing_box,
toga.Box(style=Pack(padding=5, background_color="green", height=100)))

self.main_window = toga.MainWindow(title=self.formal_name)
self.main_window.content = main_box
self.main_window.show()

def toggle_hide(self, widget):
if self.testing_box.style.visibility == "visible":
self.testing_box.style.visibility = "hidden"
else:
self.testing_box.style.visibility = "visible"
print(self.testing_box.style.visibility)

def toggle_display(self, widget):
if self.testing_box.style.display == "pack":
self.testing_box.style.display = "none"
else:
self.testing_box.style.display = "pack"
print(self.testing_box.style.display)
```

Using this to toggle the display and visibility styles you can see that display seems to have no affect.

### Expected behavior

Display would hide the element and not take up any space that the element normally would

### Screenshots

_No response_

### Environment

- Operating System: Windows 10 & Ubuntu 22.04
- Python version: 3.12
- Software versions:
- Briefcase: 0.3.22
- Toga: 0.4.9
- ...

### Logs

```

```

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the Python reproduction in the issue and compare display="none" with visibility="hidden" on Windows 10 and Ubuntu 22.04. Locate Toga's style and layout handling for display, then verify that the element no longer occupies space and add or update regression coverage for the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
css, python
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.