spectrum-web-components icon indicating copy to clipboard operation
spectrum-web-components copied to clipboard

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

Open spdev3000 opened this issue 1 year ago • 1 comments
trafficstars

Code of conduct

  • [X] I agree to follow this project's 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

spdev3000 avatar Feb 29 '24 11:02 spdev3000

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.

Westbrook avatar Feb 29 '24 15:02 Westbrook