Skip to content

Commit 52de5ee

Browse files
authored
Fix up rendering for select elements with options component (#22978)
* Fix up rendering for select elements with options component * Commit updated compiled JS * Update test case with more scenarios
1 parent a77e68f commit 52de5ee

File tree

7 files changed

+80
-4
lines changed

7 files changed

+80
-4
lines changed

src/Components/Web.JS/dist/Release/blazor.server.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/Web.JS/dist/Release/blazor.webassembly.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/Web.JS/src/Rendering/BrowserRenderer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ export class BrowserRenderer {
257257
if (newDomElementRaw instanceof HTMLSelectElement && selectValuePropname in newDomElementRaw) {
258258
const selectValue = newDomElementRaw[selectValuePropname];
259259
newDomElementRaw.value = selectValue;
260-
delete newDomElementRaw[selectValuePropname];
261260
}
262261
}
263262

src/Components/test/E2ETest/Tests/FormsTest.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,41 @@ public void InputComponentsRespondToAsynchronouslyAddedMessages()
434434
Browser.Equal("invalid", () => input.GetAttribute("class"));
435435
}
436436

437+
[Fact]
438+
public void SelectComponentSupportsOptionsComponent() {
439+
var appElement = Browser.MountTestComponent<SelectVariantsComponent>();
440+
var input = appElement.FindElement(By.Id("input-value"));
441+
var showAdditionalOptionButton = appElement.FindElement(By.Id("show-additional-option"));
442+
var selectWithComponent = appElement.FindElement(By.Id("select-with-component"));
443+
var selectWithoutComponent = appElement.FindElement(By.Id("select-without-component"));
444+
445+
// Select with custom options component and HTML component behave the
446+
// same when the selectElement.value is provided
447+
Browser.Equal("B", () => selectWithoutComponent.GetAttribute("value"));
448+
Browser.Equal("B", () => selectWithComponent.GetAttribute("value"));
449+
450+
// Reset to a value that doesn't exist
451+
input.Clear();
452+
input.SendKeys("D\t");
453+
454+
// Confirm that both values are cleared
455+
Browser.Equal("", () => selectWithComponent.GetAttribute("value"));
456+
Browser.Equal("", () => selectWithoutComponent.GetAttribute("value"));
457+
458+
// Dynamically showing the fourth option updates the selected value
459+
showAdditionalOptionButton.Click();
460+
461+
Browser.Equal("D", () => selectWithComponent.GetAttribute("value"));
462+
Browser.Equal("D", () => selectWithoutComponent.GetAttribute("value"));
463+
464+
// Change the value to one that does really doesn't exist
465+
input.Clear();
466+
input.SendKeys("F\t");
467+
468+
Browser.Equal("", () => selectWithComponent.GetAttribute("value"));
469+
Browser.Equal("", () => selectWithoutComponent.GetAttribute("value"));
470+
}
471+
437472
private Func<string[]> CreateValidationMessagesAccessor(IWebElement appElement)
438473
{
439474
return () => appElement.FindElements(By.ClassName("validation-message"))
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<option @attributes="InputAttributes">@ChildContent</option>
2+
3+
@code {
4+
[Parameter(CaptureUnmatchedValues = true)]
5+
public Dictionary<string, object> InputAttributes { get; set; }
6+
7+
[Parameter] public RenderFragment ChildContent { get; set; }
8+
}

src/Components/test/testassets/BasicTestApp/Index.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
<option value="BasicTestApp.SvgWithChildComponent">SVG with child component</option>
7676
<option value="BasicTestApp.TextOnlyComponent">Plain text</option>
7777
<option value="BasicTestApp.TouchEventComponent">Touch events</option>
78+
<option value="BasicTestApp.SelectVariantsComponent">Select with component options</option>
7879
</select>
7980

8081
<span id="runtime-info"><code><tt>@System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription</tt></code></span>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@using BasicTestApp.FormsTest
2+
3+
<input @bind="SelectValue" id="input-value"/>
4+
5+
<select @bind="SelectValue" id="select-without-component">
6+
<option value="A">Option A</option>
7+
<option value="B">Option B</option>
8+
<option value="C">Option C</option>
9+
@if (ShowAdditionalOption) {
10+
<option value="D">Option D</option>
11+
}
12+
</select>
13+
14+
<select @bind="SelectValue" id="select-with-component">
15+
<MyOption value="A">Option A</MyOption>
16+
<MyOption value="B">Option B</MyOption>
17+
<MyOption value="C">Option C</MyOption>
18+
@if (ShowAdditionalOption) {
19+
<MyOption value="D">Option D</MyOption>
20+
}
21+
</select>
22+
23+
<button @onclick="ToggleShowAdditionalOption" id="show-additional-option"> Show Additional Option</button>
24+
25+
@code
26+
{
27+
public string SelectValue { get; set; } = "B";
28+
public bool ShowAdditionalOption = false;
29+
30+
void ToggleShowAdditionalOption() {
31+
ShowAdditionalOption = true;
32+
}
33+
}

0 commit comments

Comments
 (0)