vscode-webview-ui-toolkit icon indicating copy to clipboard operation
vscode-webview-ui-toolkit copied to clipboard

vscode-dropdown JS generated option with selected property not selected

Open WebFreak001 opened this issue 3 years ago • 7 comments

Describe the bug

When generating vscode-option elements inside a vscode-dropdown and setting .selected = true; on one, it should be selected in the UI, but isn't (reset by an internal reset if no values are selected check)

To reproduce

<vscode-dropdown id="testdropdown"></vscode-dropdown>
<script>
	var dropdown = document.getElementById("testdropdown");
	for (var i = 1; i <= 3; i++)
	{
		var option = document.createElement("vscode-option");
		option.value = "v" + i;
		option.textContent = "Value " + i; // Value 1, Value 2, Value 3
		dropdown.appendChild(option);
		if (i == 2)
		{
			option.selected = true;
			// to fix bug uncomment this:
			// option.setAttribute("selected", "selected");
		}
	}
	// expected "Value 2" to be selected now
</script>

Expected behavior

Value 2 should be selected in the example, not Value 1

Desktop (please complete the following information):

  • OS Version: VSCode 1.64.0 on Electron 13.6.8 on ArchLinux i3 (X11)
  • Toolkit Version: v0.9.0

Additional context

There is an internal check ran asynchronously, which resets the value if no option is selected. However it checks if the option is selected by checking if the attribute selected is set. (not the property)

The selected property of vscode-option should probably modify the DOM attribute.

It seems to be reset here:

toolkit.js line 8715

https://github.com/microsoft/fast/blob/eff36b2834b7709cc2281738007019fd264c3d31/packages/web-components/fast-foundation/src/listbox/listbox.ts#L537

alternatively it would be possible to also check the property instead of making the property modify the attribute, which is what combobox does:

https://github.com/microsoft/fast/blob/256fe07122c2838e6bf0edd639a539b9ceeaa1bf/packages/web-components/fast-foundation/src/combobox/combobox.ts#L546

WebFreak001 avatar Feb 09 '22 20:02 WebFreak001

(made an issue in FAST: https://github.com/microsoft/fast/issues/5583)

WebFreak001 avatar Feb 09 '22 20:02 WebFreak001

Thanks for the issue and for filing an issue with FAST as well! I'll keep an eye on the progress and merge any changes the FAST team adds once they are available!

hawkticehurst avatar Feb 09 '22 22:02 hawkticehurst

any work being done on this one? I just came across this issue today using the latest webview-ui-toolkit version

CharlieGreenman avatar Mar 21 '23 17:03 CharlieGreenman

Unfortunately, no work on our end since this is an upstream issue within FAST

I've been checking the issue that @WebFreak001 filed with FAST every month or so for the last year but still haven't seen any movement on it

hawkticehurst avatar Mar 21 '23 21:03 hawkticehurst

That's pretty funny. I found a workaround via overriding component so it worked out in the end. Thank you again

CharlieGreenman avatar Mar 21 '23 22:03 CharlieGreenman

Oh nice! Glad you were able to get yourself unblocked in that case 😁

hawkticehurst avatar Mar 21 '23 22:03 hawkticehurst

That's pretty funny. I found a workaround via overriding component so it worked out in the end. Thank you again

Hi, what was your workaround?

ranitg avatar May 24 '24 07:05 ranitg