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
base: main
Are you sure you want to change the base?
Conversation
// https://drafts.csswg.org/css-fonts-4/#font-family-prop | ||
"font-family": { | ||
inherited: true, | ||
initial: "", |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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
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?
jsdom/lib/jsdom/living/helpers/style-rules.js
Lines 214 to 237 in 907daec
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}'`); | |
} |
This is my first PR to jsdom.
I tried to follow example in a8b03af. @domenic let me know if I did it correctly?