Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

danon
Copy link

@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
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
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}'`);
}

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.

None yet

2 participants