Skip to content
Closed
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a46147e
Fixed the Boolean Rendering Behavior for draggable Attribute
BrundhaVelusamy Jul 21, 2026
ccf70a4
Merge branch 'dotnet:main' into DraggableAttribute
BrundhaVelusamy Jul 21, 2026
136aa38
Merge branch 'main' into DraggableAttribute
BrundhaVelusamy Jul 23, 2026
f5d4e84
Merge branch 'main' into DraggableAttribute
BrundhaVelusamy Jul 24, 2026
d830123
Merge branch 'main' into DraggableAttribute
BrundhaVelusamy Jul 27, 2026
16069d9
Included the fix for ContentEditable and SpellCheck attributes.
BrundhaVelusamy Jul 28, 2026
25300bb
Merge branch 'DraggableAttribute' of https://github.com/BrundhaVelusa…
BrundhaVelusamy Jul 28, 2026
86543ff
Merge branch 'main' into DraggableAttribute
BrundhaVelusamy Jul 28, 2026
cb143f0
Merge branch 'main' into DraggableAttribute
BrundhaVelusamy Jul 30, 2026
aee6cc7
Merge branch 'main' into DraggableAttribute
BrundhaVelusamy Jul 31, 2026
5c4554b
Merge branch 'main' into DraggableAttribute
BrundhaVelusamy Aug 3, 2026
652ed40
Merge branch 'main' into DraggableAttribute
BrundhaVelusamy Aug 3, 2026
8ab44da
Merge branch 'main' into DraggableAttribute
BrundhaVelusamy Aug 3, 2026
1985f2f
Merge branch 'main' into DraggableAttribute
BrundhaVelusamy Aug 4, 2026
829b52b
Merge branch 'main' into DraggableAttribute
BrundhaVelusamy Aug 4, 2026
6906922
Updated the comments based on the fix
BrundhaVelusamy Aug 5, 2026
b507a0a
Merge branch 'DraggableAttribute' of https://github.com/BrundhaVelusa…
BrundhaVelusamy Aug 5, 2026
0e97df2
Merge branch 'main' into DraggableAttribute
BrundhaVelusamy Aug 5, 2026
c3a9dd0
Merge branch 'main' into DraggableAttribute
BrundhaVelusamy Aug 5, 2026
9e12c47
Merge branch 'main' into DraggableAttribute
BrundhaVelusamy Aug 6, 2026
f06f0aa
Merge branch 'main' into DraggableAttribute
BrundhaVelusamy Aug 7, 2026
89c0f54
Merge branch 'main' into DraggableAttribute
BrundhaVelusamy Oct 1, 2026
54d431c
Merge branch 'main' into DraggableAttribute
BrundhaVelusamy Oct 19, 2026
2967c38
Add regression coverage for enumerated boolean attributes
BrundhaVelusamy Oct 26, 2026
ffc8112
Merge branch 'main' into DraggableAttribute
BrundhaVelusamy Oct 27, 2026
5ad4edc
Removed the E2E test case and inline the helper function
BrundhaVelusamy Nov 12, 2026
093ecec
Merge branch 'main' into DraggableAttribute
BrundhaVelusamy Nov 12, 2026
c98584e
Merge branch 'main' into DraggableAttribute
BrundhaVelusamy Nov 12, 2026
ede600f
Fix enumerated boolean attribute serialization
BrundhaVelusamy Nov 17, 2026
65aaa41
Merge branch 'main' into DraggableAttribute
BrundhaVelusamy Nov 17, 2026
9db56e6
Addressed copilot review feedback: Added E2E coverage for enumerated …
BrundhaVelusamy Nov 18, 2026
5f3d0e4
Merge branch 'DraggableAttribute' of https://github.com/BrundhaVelusa…
BrundhaVelusamy Nov 18, 2026
8e790e4
Merge branch 'main' into DraggableAttribute
BrundhaVelusamy Nov 18, 2026
2a48ace
Merge branch 'main' into DraggableAttribute
BrundhaVelusamy Nov 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions src/Components/Components/src/Rendering/RenderTreeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ public sealed class RenderTreeBuilder : IDisposable
// On WebAssembly, bool element attributes must be stored as strings because the JS
// shared memory render batch reader cannot distinguish boxed bools from strings.
private static readonly object ElementBoolTrueValue = OperatingSystem.IsBrowser() ? string.Empty : BoxedTrue;

// HTML enumerated attributes that accept "true"/"false" string values must be rendered
// with explicit string values rather than as presence/absence attributes.
// If rendered as bare attributes (e.g., <div draggable>), browsers may not honor them correctly.
private static readonly HashSet<string> EnumeratedBoolAttributes =
Comment thread
BrundhaVelusamy marked this conversation as resolved.
Resolved
Comment thread
BrundhaVelusamy marked this conversation as resolved.
Resolved
new(StringComparer.OrdinalIgnoreCase) { "draggable", "spellcheck", "contenteditable" };
Comment thread
BrundhaVelusamy marked this conversation as resolved.
Resolved

private static readonly string ComponentReferenceCaptureInvalidParentMessage = $"Component reference captures may only be added as children of frames of type {RenderTreeFrameType.Component}";

private readonly RenderTreeFrameArrayBuilder _entries = new RenderTreeFrameArrayBuilder();
Expand Down Expand Up @@ -183,7 +190,8 @@ public void AddAttribute(int sequence, string name)
/// </para>
/// <para>
/// The attribute is associated with the most recently added element. If the value is <c>false</c> and the
/// current element is not a component, the frame will be omitted.
/// current element is not a component, the frame will be omitted, except for HTML enumerated attributes
/// such as <c>draggable</c>, <c>spellcheck</c>, and <c>contenteditable</c>, which render <c>"false"</c>.
/// </para>
/// </summary>
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
Expand All @@ -196,6 +204,10 @@ public void AddAttribute(int sequence, string name, bool value)
{
_entries.AppendAttribute(sequence, name, value ? BoxedTrue : BoxedFalse);
}
else if (IsEnumeratedBoolAttribute(name))
Comment thread
BrundhaVelusamy marked this conversation as resolved.
Resolved
{
_entries.AppendAttribute(sequence, name, value ? "true" : "false");
Comment thread
BrundhaVelusamy marked this conversation as resolved.
Resolved
}
else if (value)
{
// Don't add 'false' attributes for elements. We want booleans to map to the presence
Expand Down Expand Up @@ -350,7 +362,8 @@ public void AddAttribute<TArgument>(int sequence, string name, EventCallback<TAr
/// Appends a frame representing a string-valued attribute.
/// The attribute is associated with the most recently added element. If the value is <c>null</c>, or
/// the <see cref="System.Boolean" /> value <c>false</c> and the current element is not a component, the
/// frame will be omitted.
/// frame will be omitted, except for HTML enumerated attributes such as <c>draggable</c>, <c>spellcheck</c>,
/// and <c>contenteditable</c>, which render <c>"false"</c>.
/// </summary>
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
/// <param name="name">The name of the attribute.</param>
Expand All @@ -368,7 +381,11 @@ public void AddAttribute(int sequence, string name, object? value)
}
else if (value is bool boolValue)
{
if (boolValue)
if (IsEnumeratedBoolAttribute(name))
{
_entries.AppendAttribute(sequence, name, boolValue ? "true" : "false");
Comment thread
BrundhaVelusamy marked this conversation as resolved.
Resolved
}
Comment thread
javiercn marked this conversation as resolved.
Resolved
else if (boolValue)
{
_entries.AppendAttribute(sequence, name, ElementBoolTrueValue);
}
Expand Down Expand Up @@ -915,6 +932,13 @@ internal void TrackAttributeName(string name)
seenAttributeNames[name] = _entries.Count; // See comment in ProcessAttributes for why this is OK.
}

private static bool IsEnumeratedBoolAttribute(string name)
Comment thread
BrundhaVelusamy marked this conversation as resolved.
Resolved
{
// Enumerated attributes (draggable, spellcheck, contenteditable) are not subject to the
// standard HTML boolean attribute rules. They require explicit "true"/"false" string values.
return EnumeratedBoolAttributes.Contains(name);
}

/// <inheritdoc />
public void Dispose()
{
Expand Down
225 changes: 225 additions & 0 deletions src/Components/Components/test/Rendering/RenderTreeBuilderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,58 @@ public void AddAttribute_Element_BoolFalse_IgnoresFrame()
frame => AssertFrame.Element(frame, "elem", 1, 0));
}

[Theory]
[InlineData(true, "true")]
[InlineData(false, "false")]
public void AddAttribute_Element_DraggableBool_AddsFrameWithExplicitStringValue(bool value, string expected)
{
var builder = new RenderTreeBuilder();

builder.OpenElement(0, "div");
builder.AddAttribute(1, "draggable", value);
builder.CloseElement();

Assert.Collection(
builder.GetFrames().AsEnumerable(),
frame => AssertFrame.Element(frame, "div", 2, 0),
frame => AssertFrame.Attribute(frame, "draggable", expected, 1));
}

[Theory]
[InlineData("draggable", "true")]
[InlineData("DRAGGABLE", "false")]
[InlineData("Draggable", "true")]
public void AddAttribute_Element_DraggableAttributeName_IsMatchedCaseInsensitively(string attributeName, string expected)
{
var builder = new RenderTreeBuilder();

builder.OpenElement(0, "div");
builder.AddAttribute(1, attributeName, bool.Parse(expected));
builder.CloseElement();

Assert.Collection(
builder.GetFrames().AsEnumerable(),
frame => AssertFrame.Element(frame, "div", 2, 0),
frame => AssertFrame.Attribute(frame, attributeName, expected, 1));
}

[Theory]
[InlineData(false)]
[InlineData(true)]
public void AddAttribute_Component_DraggableBool_SetsAttributeValue(bool value)
{
var builder = new RenderTreeBuilder();

builder.OpenComponent<TestComponent>(0);
builder.AddAttribute(1, "draggable", value);
builder.CloseComponent();

Assert.Collection(
builder.GetFrames().AsEnumerable(),
frame => AssertFrame.Component<TestComponent>(frame, 2, 0),
frame => AssertFrame.Attribute(frame, "draggable", value, 1));
}

[Theory]
[InlineData(false)]
[InlineData(true)]
Expand Down Expand Up @@ -1398,6 +1450,23 @@ public void AddAttribute_Element_ObjectBoolFalse_IgnoresFrame()
frame => AssertFrame.Element(frame, "elem", 1, 0));
}

[Theory]
[InlineData(true, "true")]
[InlineData(false, "false")]
public void AddAttribute_Element_ObjectDraggableBool_AddsFrameWithExplicitStringValue(bool value, string expected)
{
var builder = new RenderTreeBuilder();

builder.OpenElement(0, "div");
builder.AddAttribute(1, "draggable", (object)value);
builder.CloseElement();

Assert.Collection(
builder.GetFrames().AsEnumerable(),
frame => AssertFrame.Element(frame, "div", 2, 0),
frame => AssertFrame.Attribute(frame, "draggable", expected, 1));
}

[Theory]
[InlineData(false)]
[InlineData(true)]
Expand Down Expand Up @@ -1952,6 +2021,162 @@ public void ProcessDuplicateAttributes_SilentFrameFollowedBySameAttribute()
f => AssertFrame.Attribute(f, "id", "bye"));
}

[Theory]
[InlineData(true, "true")]
[InlineData(false, "false")]
public void AddAttribute_Element_SpellcheckBool_AddsFrameWithExplicitStringValue(bool value, string expected)
{
var builder = new RenderTreeBuilder();

builder.OpenElement(0, "div");
builder.AddAttribute(1, "spellcheck", value);
builder.CloseElement();

Assert.Collection(
builder.GetFrames().AsEnumerable(),
frame => AssertFrame.Element(frame, "div", 2, 0),
frame => AssertFrame.Attribute(frame, "spellcheck", expected, 1));
}

[Theory]
[InlineData("spellcheck", true, "true")]
[InlineData("SPELLCHECK", false, "false")]
[InlineData("Spellcheck", true, "true")]
public void AddAttribute_Element_SpellcheckAttributeName_IsMatchedCaseInsensitively(string attributeName, bool value, string expected)
{
var builder = new RenderTreeBuilder();

builder.OpenElement(0, "div");
builder.AddAttribute(1, attributeName, value);
builder.CloseElement();

Assert.Collection(
builder.GetFrames().AsEnumerable(),
frame => AssertFrame.Element(frame, "div", 2, 0),
frame => AssertFrame.Attribute(frame, attributeName, expected, 1));
}

[Theory]
[InlineData(true, "true")]
[InlineData(false, "false")]
public void AddAttribute_Element_ObjectSpellcheckBool_AddsFrameWithExplicitStringValue(bool value, string expected)
{
var builder = new RenderTreeBuilder();

builder.OpenElement(0, "div");
builder.AddAttribute(1, "spellcheck", (object)value);
builder.CloseElement();

Assert.Collection(
builder.GetFrames().AsEnumerable(),
frame => AssertFrame.Element(frame, "div", 2, 0),
frame => AssertFrame.Attribute(frame, "spellcheck", expected, 1));
}

[Theory]
[InlineData(false)]
[InlineData(true)]
public void AddAttribute_Component_SpellcheckBool_SetsAttributeValue(bool value)
{
var builder = new RenderTreeBuilder();

builder.OpenComponent<TestComponent>(0);
builder.AddAttribute(1, "spellcheck", value);
builder.CloseComponent();

Assert.Collection(
builder.GetFrames().AsEnumerable(),
frame => AssertFrame.Component<TestComponent>(frame, 2, 0),
frame => AssertFrame.Attribute(frame, "spellcheck", value, 1));
}

[Theory]
[InlineData(true, "true")]
[InlineData(false, "false")]
public void AddAttribute_Element_ContenteditableBool_AddsFrameWithExplicitStringValue(bool value, string expected)
{
var builder = new RenderTreeBuilder();

builder.OpenElement(0, "div");
builder.AddAttribute(1, "contenteditable", value);
builder.CloseElement();

Assert.Collection(
builder.GetFrames().AsEnumerable(),
frame => AssertFrame.Element(frame, "div", 2, 0),
frame => AssertFrame.Attribute(frame, "contenteditable", expected, 1));
}

[Theory]
[InlineData("contenteditable", true, "true")]
[InlineData("CONTENTEDITABLE", false, "false")]
[InlineData("ContentEditable", true, "true")]
public void AddAttribute_Element_ContenteditableAttributeName_IsMatchedCaseInsensitively(string attributeName, bool value, string expected)
{
var builder = new RenderTreeBuilder();

builder.OpenElement(0, "div");
builder.AddAttribute(1, attributeName, value);
builder.CloseElement();

Assert.Collection(
builder.GetFrames().AsEnumerable(),
frame => AssertFrame.Element(frame, "div", 2, 0),
frame => AssertFrame.Attribute(frame, attributeName, expected, 1));
}

[Theory]
[InlineData(true, "true")]
[InlineData(false, "false")]
public void AddAttribute_Element_ObjectContenteditableBool_AddsFrameWithExplicitStringValue(bool value, string expected)
{
var builder = new RenderTreeBuilder();

builder.OpenElement(0, "div");
builder.AddAttribute(1, "contenteditable", (object)value);
builder.CloseElement();

Assert.Collection(
builder.GetFrames().AsEnumerable(),
frame => AssertFrame.Element(frame, "div", 2, 0),
frame => AssertFrame.Attribute(frame, "contenteditable", expected, 1));
}

[Theory]
[InlineData(false)]
[InlineData(true)]
public void AddAttribute_Component_ContenteditableBool_SetsAttributeValue(bool value)
{
var builder = new RenderTreeBuilder();

builder.OpenComponent<TestComponent>(0);
builder.AddAttribute(1, "contenteditable", value);
builder.CloseComponent();

Assert.Collection(
builder.GetFrames().AsEnumerable(),
frame => AssertFrame.Component<TestComponent>(frame, 2, 0),
frame => AssertFrame.Attribute(frame, "contenteditable", value, 1));
}

[Theory]
[InlineData("disabled", true)]
[InlineData("hidden", true)]
[InlineData("readonly", true)]
public void AddAttribute_Element_RegularBoolAttribute_NotAffectedByEnumeratedLogic(string attributeName, bool value)
{
var builder = new RenderTreeBuilder();

builder.OpenElement(0, "div");
builder.AddAttribute(1, attributeName, value);
builder.CloseElement();

Assert.Collection(
builder.GetFrames().AsEnumerable(),
frame => AssertFrame.Element(frame, "div", 2, 0),
frame => AssertFrame.Attribute(frame, attributeName, 1));
Comment thread
BrundhaVelusamy marked this conversation as resolved.
Resolved
}

[Fact]
public void ProcessDuplicateAttributes_DoesNotRemoveDuplicatesInsideChildElement()
{
Expand Down
26 changes: 26 additions & 0 deletions src/Components/Web/test/HtmlRendering/HtmlRendererTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,32 @@ await htmlRenderer.Dispatcher.InvokeAsync(async () =>
});
}

[Theory]
[InlineData(true, "true")]
[InlineData(false, "false")]
public async Task RenderComponentAsync_RendersDraggableAttributeWithExplicitStringValue(bool value, string expected)
Comment thread
BrundhaVelusamy marked this conversation as resolved.
Resolved
{
// Arrange
var expectedHtml = new[] { "<", "div", " ", "draggable", "=", "\"", expected, "\"", ">", "Drag Me", "</", "div", ">" };
var serviceProvider = GetServiceProvider(collection => collection.AddSingleton(new RenderFragment(rtb =>
{
rtb.OpenElement(0, "div");
rtb.AddAttribute(1, "draggable", value);
rtb.AddContent(2, "Drag Me");
rtb.CloseElement();
})));

var htmlRenderer = GetHtmlRenderer(serviceProvider);
await htmlRenderer.Dispatcher.InvokeAsync(async () =>
{
// Act
var result = await htmlRenderer.RenderComponentAsync<TestComponent>();

// Assert
AssertHtmlContentEquals(expectedHtml, result);
});
}

[Fact]
public async Task RenderComponentAsync_CanRenderWithChildren()
{
Expand Down
Loading