Skip to content

Added Selection widget to Toga web #3402

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

Merged
merged 9 commits into from
May 23, 2025
Merged

Conversation

vt37
Copy link
Contributor

@vt37 vt37 commented May 2, 2025

Added a Selection widget on web platform and updated related documentations.

Previously, Selection widget can't run on the web backend

Refs #3334

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good first pass; a couple of comments inline.

Two other details that I noticed in manual testing (using the selection example):

  1. The initial value of the widgets don't appear to be applied. The widgets are all empty on application startup
  2. The buttons (print, carbon, ytterbium, thulium) don't do anything. The three elements should change the value of the first selection, with print displaying the current value and an attribute associated with the currently selected value.

Also - a reminder of what I mentioned in one of our recent calls: If you're presenting code without tests, it's important to describe how you've tested something. Without any additional detail, my immediate reaction was to try the Selection example - which revealed the problems I described here.

@@ -12,7 +12,6 @@
from .widgets.activityindicator import ActivityIndicator
from .widgets.box import Box
from .widgets.button import Button
from .widgets.dateinput import DateInput
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you've got a messy merge here somewhere - the DateInput has been deleted.


def create(self):
self.native = self._create_native_widget("sl-select")
self.native.addEventListener("sl-change", create_proxy(self.dom_onchange))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency - the signal is sl-change, so the handler should be dom_sl_change.

Suggested change
self.native.addEventListener("sl-change", create_proxy(self.dom_onchange))
self.native.addEventListener("sl-change", create_proxy(self.dom_sl_change))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably merge the (currently 3, could be more?) release notes into a single 3334.feature.rst release note"

The Web backend now provides DateInput, ScrollContainer and Selection widgets.

If we get another widget before the release this week, a change to an existing release note will meet the towncrier requirement.

Comment on lines 22 to 23
option.value = display_text
option.textContent = display_text
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"value" and "text content" are different attributes for a reason - the text labels in the selection don't have to be unique. The approach you're using here for identifying the currently selected index will always find the first matching text label.

If Shoelace doesn't provide a native index-based selection mechanism, then you can use the value field to track the index.

@@ -62,7 +62,6 @@ def not_implemented(feature):
"Button",
# 'Canvas',
"Divider",
"DateInput",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More of the messy merge here

@vt37
Copy link
Contributor Author

vt37 commented May 3, 2025

Looks like a good first pass; a couple of comments inline.

Two other details that I noticed in manual testing (using the selection example):

1. The initial value of the widgets don't appear to be applied. The widgets are all empty on application startup

2. The buttons (print, carbon, ytterbium, thulium) don't do anything. The three elements should change the value of the first selection, with print displaying the current value and an attribute associated with the currently selected value.

Also - a reminder of what I mentioned in one of our recent calls: If you're presenting code without tests, it's important to describe how you've tested something. Without any additional detail, my immediate reaction was to try the Selection example - which revealed the problems I described here.

Thanks for the feedback! Sorry about that, I assumed that since I didn’t write and use an external test file, the example itself would be considered the test. My mistake on that. But yes, I used the selection example as my testing method and manually verified the widget through it. I’ll address the issues you pointed out and make sure it'll work as expected. Thanks again!

@vt37
Copy link
Contributor Author

vt37 commented May 19, 2025

Apologies for the delay in fixing the issue. It turns out the Selection widget behavior was also related to issue #3451, which affected the button interaction logic in the example. I've opened a separate pull request (#3466) to address that issue. I've now pushed an update here that should correctly set the initial value and connect the buttons as expected.

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now looks really good; thanks for those updates. And apologies for messing up the button handling - that's all on me!

@freakboy3742 freakboy3742 merged commit 4a37fff into beeware:main May 23, 2025
52 checks passed
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

Successfully merging this pull request may close these issues.

2 participants