Skip to content

Commit f03bf06

Browse files
chriseppsteinamiller-gh
authored andcommitted
fix: Correct the SourceAttributes returned by new State model.
The source attributes for the state attribute required handling for universal states and also it was no longer including the class's source attributes.
1 parent 1896efd commit f03bf06

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

Diff for: packages/css-blocks/src/Block/BlockClass.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Attribute } from "@opticss/element-analysis";
1+
import { Attribute, AttributeValue, attrValues } from "@opticss/element-analysis";
22

33
import { UNIVERSAL_STATE } from "../BlockSyntax";
44
import { OptionsReader } from "../OptionsReader";
@@ -94,9 +94,13 @@ export class BlockClass extends Style<BlockClass, Block, Block, StateGroup> {
9494
*/
9595
public asSource(): string { return `.${this.name}`; }
9696

97-
public asSourceAttributes(): Attribute[] {
97+
public asSourceAttributes(optionalRoot = false): Attribute[] {
9898
if (!this._sourceAttribute) {
99-
this._sourceAttribute = new Attribute("class", { constant: this.name });
99+
let value: AttributeValue = { constant: this.name };
100+
if (optionalRoot && this.isRoot) {
101+
value = attrValues.oneOf([value, attrValues.absent()]);
102+
}
103+
this._sourceAttribute = new Attribute("class", value);
100104
}
101105
return [this._sourceAttribute];
102106
}

Diff for: packages/css-blocks/src/Block/State.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
Attr,
33
AttributeNS,
4+
attrValues,
45
} from "@opticss/element-analysis";
56
import { assertNever, assertNeverCalled } from "@opticss/util";
67

@@ -59,8 +60,11 @@ export class State extends Style<State, Block, StateGroup, never> {
5960

6061
asSourceAttributes(): Attr[] {
6162
if (!this._sourceAttributes) {
62-
this._sourceAttributes = [];
63-
this._sourceAttributes.push(new AttributeNS("state", this.parent.name, { constant: this.name }));
63+
let blockClass = this.blockClass;
64+
let rootIsOptional = true;
65+
this._sourceAttributes = blockClass.asSourceAttributes(rootIsOptional);
66+
let value = this.isUniversal ? attrValues.absent() : attrValues.constant(this.name);
67+
this._sourceAttributes.push(new AttributeNS("state", this.parent.name, value));
6468
}
6569
return this._sourceAttributes.slice();
6670
}

0 commit comments

Comments
 (0)