-
Notifications
You must be signed in to change notification settings - Fork 213
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
Picker fails to update when adding a new item and setting as the current value #1331
Comments
This is the fix that I'm theorizing right now: https://webcomponents.dev/edit/G5DPiQudnGayyu9qO9ze/src/index.ts. I'll submit a PR for this, as I see it as a qualitatively better solution that what's currently available. I do think it's a bit short term, however. The ability to place items directly into the While While this solution works when It's also possible that I'm over thinking this. For instance when you visit https://webcomponents.dev/edit/biTK3akZblgHf3d0RDYX/src/index.js across various browsers in macOS; Chrome will actually close/open the menu for you when you add the new options, Firefox does exactly what you'd expect, and Safari does not allow the new option until you've manually closed and opened the menu. So, we're not in the worst of company struggling a little bit as far as how to address this. In the |
I have also been trying to workaround these problems the last days (using @spectrum-web-components/picker 0.4.4) in a project where we need to replace the options in a sp-picker depending on which options the user selects elsewhere in the user interface. We tried adding additional workaround code to manually close the picker if it was open, and then wait until all the sp-menu-item elements was moved back before re-rendering our own component, but then we got into problems with setting the values. Adding additional code to set It would be super helpful if possible to ensure that both sp-picker and all of its child sp-menu-item elements always have their properties in sync. Maybe a MutationObserver or similar is needed to ensure that. I can see that it is tricky as the API surface is large and in this case even spans over more than one component. Thanks for an otherwise visually nice looking set of components. Fingers crossed for a good solution for this soon. |
@tirithen would you be able to share a repro on the situation you are seeing here? I’d love to ensure that it’s supported by our API, but I’m not fully clear on your workflow here. Thanks in advance. |
Thanks for the reply, I would appreciate that but I need some time to break it out to a minimal setup as sp-picker is part of another lit-element component that in turn is used in a Vue app.
UX vice it is about allowibg the end user to restrict the options for a sp-picker by toggling sp-switch elements to exclude options on the sp-picker. Therefore we need to re-render the sp-menu-item elements inside the sp-picker, and also ideally keeping the state/value of the sp-picker (as long as the selected value was not removed).
I'll try to create a repo with a more minimal setup during the coming days to help pinpoint the problems.
3 maj 2021 18:57:22 Westbrook Johnson ***@***.***>:
… @tirithen[https://github.com/tirithen] would you be able to share a repro on the situation you are seeing here? I’d love to ensure that it’s supported by our API, but I’m not fully clear on your workflow here. Thanks in advance.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub[#1331 (comment)], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AAB4AM6JQGTKED6OTKDIX3TTL3IXDANCNFSM42AWS4WA].
[data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAABICAYAAABV7bNHAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAArSURBVHic7cEBDQAAAMKg909tDjegAAAAAAAAAAAAAAAAAAAAAAAAAAA+DFFIAAEctgHwAAAAAElFTkSuQmCC###24x24:true###][Spårningsbild][https://github.com/notifications/beacon/AAB4AM4FPPJM56LPHMZ4TALTL3IXDA5CNFSM42AWS4WKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOGGHA5YQ.gif]
|
@tirithen, maybe this could help? https://webcomponents.dev/edit/xLImpVq4PYA0HUQdls6q/src/index.ts Here, the first picker chooses how many options will display in the second picker. The update button toggles between the two lists of options for the second picker and ensures the first picker stays up to date. Super contrived, but maybe it sheds some light on what you're looking to do here? |
@Westbrook sorry for late reply, the example you setup made the issues I have easy to reproduce, thanks, also a really nice page to experiment and share web components. :) I made the A GIF showing the extra options and the crash when it fails to replace an element, probably as it is currently moved elsewhere as the dropdown is open. The component keeps copies of the old options and eventually crashes, it seem to happen especially when the dropdown is open. Maybe if you would clone the elements instead of detaching/attaching them to the DOM it might be easier to prevent those kind of crashes/duplications. It it tricky as the API surface of components are large and all properties/attributes and in this case children need to be in sync at all times. The modified version: https://webcomponents.dev/edit/phC1LLFUDc4QdHapBAqr/src/index.ts To reproduce:
It is a nice looking component so looking forward to using it once it is working, meanwhile I resorted to a plain There was also problems with assigning the selected value in the project I worked on, but I'm afraid that I do not currently remember how to reproduce, anyhow this is probably a good starting point, maybe that will also work better once these bugs have been taken care of. And again, thanks for an otherwise nice looking and easy to use component library. |
Thanks for the reproduction case. I definitely would not expect this to work right now based on the approach we take to managing these elements. Your best hope at a work around today would be to know you are receiving new options, close the menu, apply the new options, and reopen the menu. It's possible that future work could support this, but I'm not sure when we'd be able to prioritize addressing this. In theory the concepts underlying this change are being researched right now in our Combobox patter development, but how soon that completes and whether or not we choose to bring the ideas applied there in back to the Picker UI is as yet unclear. Under a short review of the browser ecosystem for this, it also seems that the native In the link above with macOS you'll see Chrome visibly close and the reopen the In Safari, the menu contents will NOT change while open. Closing and opening again will display an update (at yet once again static) list of Firefox seems to work as expected adding the |
No problem :) I guess that it does not matter much whether the dropdown closes or not when the options are updated, the problem is when it crashes, or the old child option tags stays and become out of sync with the options property as that makes the component unreliable. We did some tests to workaround by trying to detect if the dropdown was open or not, but it simply got to complex. As the open property acts as a setter to change the state I guess that the As the public API consists of several properties (.options, .open, .selectedItem) and child Just as a suggestion, if the children was copied instead of moved to the end of the tag, maybe the .open property would not need to be as tightly coupled with the others as the options could then update independent of the open state. |
Will be addressed by #2086 |
Expected Behaviour
During a single render update, I should be able to add a new item to my data model driving the menu-items, as well as selecting this new item. The label should update to the current value and reflect that it exists in the list by using non-placeholder (non-italic) text
Actual Behaviour
The picker label does not update when adding a new item and selecting it
Reproduce Scenario (including but not limited to)
https://webcomponents.dev/edit/iiBMUXs1JiTFL6Hf4y9A/src/index.ts
Steps to Reproduce
Create a button to add menu-items and make the selection. Click the button and watch the label not udpate
Platform and Version
Picker 0.3.1 on Chrome
The text was updated successfully, but these errors were encountered: