Skip to content

Implement getComputedStyle() for font-family (#3614)#3615

Closed
danon wants to merge 1 commit intojsdom:mainfrom
danon:master
Closed

Implement getComputedStyle() for font-family (#3614)#3615
danon wants to merge 1 commit intojsdom:mainfrom
danon:master

Conversation

@danon
Copy link
Copy Markdown

@danon danon commented Oct 27, 2023

This is my first PR to jsdom.

I tried to follow example in a8b03af. @domenic let me know if I did it correctly?

// https://drafts.csswg.org/css-fonts-4/#font-family-prop
"font-family": {
inherited: true,
initial: "",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this needs to be set to something like "serif". Can you do that, and then update the test? https://jsbin.com/tulemoreka/edit?html,output

"font-family": {
inherited: true,
initial: "",
computedValue: "as-specified"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't appear correct. Per spec it's

list, each item a string and/or keywords

The appropriate test to add is something like

<div style="font-family: serif,sans-serif,     'Times New Roman',Arial"></div>

and then testing that the computed style is serif, sans-serif, "Times New Roman", Arial (with the right quotes and spacing).

Making that work correctly would involve introducing some new infrastructure, probably around here?

function getComputedValue(element, property) {
const { computedValue, initial } = exports.propertiesWithResolvedValueImplemented[property];
if (computedValue === "as-specified") {
return getSpecifiedValue(element, property);
} else if (computedValue === "computed-color") {
const specifiedValue = getSpecifiedValue(element, property);
// https://drafts.csswg.org/css-color-4/#resolving-other-colors
if (specifiedValue === "currentcolor") {
if (property === "color") {
if (element.parentElement !== null) {
return getComputedValue(element.parentElement, "color");
}
return initial;
}
return getComputedValue(element, "color");
}
return getComputedOrUsedColor(specifiedValue);
}
throw new TypeError(`Internal error: unrecognized computed value instruction '${computedValue}'`);
}

Smooth-Programmer

This comment was marked as spam.

asamuzaK added a commit to asamuzaK/jsdom that referenced this pull request Apr 4, 2026
asamuzaK added a commit to asamuzaK/jsdom that referenced this pull request Apr 4, 2026
asamuzaK added a commit to asamuzaK/jsdom that referenced this pull request Apr 4, 2026
@domenic domenic closed this in 4097d66 Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants