adobe / spectrum-web-components

Spectrum Web Components
https://opensource.adobe.com/spectrum-web-components/
Apache License 2.0
1.26k stars 200 forks source link

[Feat]: Support validation of Picker value without rendered child items #4101

Open spdev3000 opened 7 months ago

spdev3000 commented 7 months ago

Code of conduct

Impacted component(s)

Picker

Expected behavior

When user renders a Picker that have already a value set, but the values of the menu-items will be set after initialization - Picker should run some re-comparing and update the current selection state visible in the Picker.

Actual behavior

When user renders a Picker that have already a value set, but the values of the menu-items will be set after initialization (as this happens sometimes in our project) - the value won't be re-compared to selected value and no selection will be shown in Picker.

Screenshots

No response

What browsers are you seeing the problem in?

Chrome

How can we reproduce this issue?

  1. Go to https://studio.webcomponents.dev/edit/fFmXO9B4RPvJVzr9Hbp1/src/index.ts?p=stories
  2. Compare both Pickers and their current selection

Sample code that illustrates the problem

No response

Logs taken while reproducing problem

No response

Westbrook commented 7 months ago

FYI: this is "not a bug" in that those items are required for the Picker to validate itself. I've updated the issue title and labelling to outline this as a feature request for that reason. This does align with some research that we have planned, however I can't speak to any timing around that research having any practical side effects at this time.

If you know the value at initial render, and would like not to append the items/their values, you may look into inserting a dummy Item that possessed that value and removing that when the actual values were later available. Or, if it were acceptable to your interface, you could leave the Picker without a value until you were prepared to populate the Items and then supply a value at that point, when it would actually be possible to validate that value.