diff --git a/src/browser/tests/element/css_style_properties.html b/src/browser/tests/element/css_style_properties.html index e2ce4e3b8..3100d2cd2 100644 --- a/src/browser/tests/element/css_style_properties.html +++ b/src/browser/tests/element/css_style_properties.html @@ -60,6 +60,16 @@ div.style.setProperty('float', 'right'); testing.expectEqual('right', div.style.cssFloat); + + // undefined stringifies to "undefined", it doesn't clear the declaration + // (Chrome rejects the invalid value and keeps 'right'; we don't validate yet) + div.style.cssFloat = undefined; + testing.expectEqual(false, div.style.cssFloat === ''); + + // [LegacyNullToEmptyString]: null removes it + div.style.cssFloat = null; + testing.expectEqual('', div.style.cssFloat); + testing.expectEqual('', div.style.cssText); } diff --git a/src/browser/webapi/css/CSSStyleDeclaration.zig b/src/browser/webapi/css/CSSStyleDeclaration.zig index 0d66df276..b23142e01 100644 --- a/src/browser/webapi/css/CSSStyleDeclaration.zig +++ b/src/browser/webapi/css/CSSStyleDeclaration.zig @@ -485,11 +485,13 @@ fn getFloat(self: *const CSSStyleDeclaration, frame: *Frame) []const u8 { return self.getPropertyValue("float", frame); } -fn setFloat(self: *CSSStyleDeclaration, value_: ?[]const u8, frame: *Frame) !void { +fn setFloat(self: *CSSStyleDeclaration, value: js.Value, frame: *Frame) !void { if (self._is_computed) { return error.NoModificationAllowed; } - if (try self.setPropertyImpl("float", value_ orelse "", false, frame)) { + // `[LegacyNullToEmptyString] CSSOMString`: null becomes "", undefined becomes "undefined". + const str = if (value.isNull()) "" else try value.toZig([]const u8); + if (try self.setPropertyImpl("float", str, false, frame)) { try self.syncStyleAttribute(frame); } }