Skip to content
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

Fix select #4499

Merged
merged 10 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Fixed `SelectionList` issues after removing an option https://github.com/Textualize/textual/pull/4464
- Fixed `ListView` bugs with the initial index https://github.com/Textualize/textual/pull/4452
- Fixed `Select` not closing https://github.com/Textualize/textual/pull/4499
- Fixed setting `loading=False` removing all child loading indicators https://github.com/Textualize/textual/pull/4499

### Changed

Expand All @@ -19,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added

- Added `message_signal` to MessagePump, to listen to events sent to another widget. https://github.com/Textualize/textual/pull/4487
- Added `Widget.suppress_click` https://github.com/Textualize/textual/pull/4499

## [0.58.1] - 2024-05-01

Expand Down
25 changes: 20 additions & 5 deletions src/textual/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,15 +625,21 @@ def set_loading(self, loading: bool) -> Awaitable:
Returns:
An optional awaitable.
"""

LOADING_INDICATOR_CLASS = "-textual-loading-indicator"
if loading:
loading_indicator = self.get_loading_widget()
loading_indicator.add_class("-textual-loading-indicator")
loading_indicator.add_class(LOADING_INDICATOR_CLASS)
await_mount = self.mount(loading_indicator)
return await_mount
else:
await_remove = self.query(".-textual-loading-indicator").remove()
return await_remove
for child in self.children:
if child.has_class(LOADING_INDICATOR_CLASS):
return child.remove()

async def dummy() -> None:
"""Do nothing if there is no indicator."""

return dummy()

async def _watch_loading(self, loading: bool) -> None:
"""Called when the 'loading' reactive is changed."""
Expand Down Expand Up @@ -3302,6 +3308,15 @@ def get_style_at(self, x: int, y: int) -> Style:
return Style()
return self.screen.get_style_at(*screen_offset)

def suppress_click(self) -> None:
"""Suppress a click event.

This will prevent a [Click][textual.events.Click] event being sent,
if called after a mouse down event and before the click itself.

"""
self.app._mouse_down_widget = None

def _forward_event(self, event: events.Event) -> None:
event._set_forwarded()
self.post_message(event)
Expand Down Expand Up @@ -3519,7 +3534,7 @@ def focus(self, scroll_visible: bool = True) -> Self:
The `Widget` instance.
"""

def set_focus(widget: Widget):
def set_focus(widget: Widget) -> None:
"""Callback to set the focus."""
try:
widget.screen.set_focus(self, scroll_visible=scroll_visible)
Expand Down
2 changes: 2 additions & 0 deletions src/textual/widgets/_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def action_dismiss(self) -> None:
def _on_blur(self, _event: events.Blur) -> None:
"""On blur we want to dismiss the overlay."""
self.post_message(self.Dismiss(lost_focus=True))
self.suppress_click()

def on_option_list_option_selected(self, event: OptionList.OptionSelected) -> None:
"""Inform parent when an option is selected."""
Expand Down Expand Up @@ -177,6 +178,7 @@ def _watch_has_value(self, has_value: bool) -> None:

async def _on_click(self, event: events.Click) -> None:
"""Inform ancestor we want to toggle."""
event.stop()
self.post_message(self.Toggle())


Expand Down