-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Set font size slider to 1 as default, em units #3090
Conversation
Addresses #2716 |
Codecov Report
@@ Coverage Diff @@
## master #3090 +/- ##
=========================================
- Coverage 32.25% 31% -1.25%
=========================================
Files 216 222 +6
Lines 6148 6818 +670
Branches 1080 1265 +185
=========================================
+ Hits 1983 2114 +131
- Misses 3515 3907 +392
- Partials 650 797 +147
Continue to review full report at Codecov.
|
blocks/library/paragraph/index.js
Outdated
@@ -198,7 +205,7 @@ registerBlockType( 'core/paragraph', { | |||
const styles = { | |||
backgroundColor: backgroundColor, | |||
color: textColor, | |||
fontSize: fontSize, | |||
fontSize: fontSize ? fontSize + 'em' : undefined, |
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.
What happens if the theme sets a font size on the paragraph in a stylesheet? Then it would base the font size on the parent node, right? https://developer.mozilla.org/en-US/docs/Web/CSS/font-size#Ems
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.
Yeah, that's why I thought that em
was the right choice. The theme should be setting the base font size, and the font size slider is there to make it bigger or smaller. Or am I misunderstanding the issue?
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.
Yes, em
works in that way, but ideally it would be relative to the normal font size of that element, rather than the font size of the parent element. See #2610 (comment). Many themes target the paragraph directly, e.g. .content p { font-size: 16px }
. In this case, I think it would break?
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.
I'm not sure... from what I can see, it would be fine. Here's how we currently set the font size on paragraphs in the editor:
.editor-visual-editor p {
font-family: "Noto Serif", serif;
font-size: 16px;
line-height: 1.8;
}
Applying a font-size
in the paragraph's style attribute seems to accept 16px as the same as 1em, and it works as I expected. (I compared an unstyled paragraph to one with font-size set to 1em, they were identical) Perhaps I'm missing some detail though?
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.
I was missing a detail. It was coincidence it worked. Thanks for putting me on the right track here.
Hi @notnownikki, nice work here, this generally works as advertised. During my tests I found some regressions that should be corrected. I think both of this problems are related with the addition of the span element. The span element was added to make the font-size relative to the default size of a paragraph. |
As I remember, there were discussions that we shouldn't take this approach, and let themes register font sizes that the slider uses. |
Yes, we need to revise this a bit more generally, and probably go with a stepped slider that covers classes like The current implementation in master would either be a fallback or a "custom" option. |
This approach where we use a slider that just set classes |
Yes, and that allows us to just apply a class to the |
@notnownikki, I can try to create a PR with that approach so we can look at how the approach looks, would that be ok? Or given that you already started you would prefer to continue the work on this and update this PR / create a new one? |
From the comments above, this PR should be closed, am I right? |
Oh, yes, sorry. I missed the last message on here. This should be closed in favor of theme supplied sizes. |
Description
How Has This Been Tested?
Started a new post, typed some text, used the slider to resize it, checking the default value of 1 was set first.
Opened saved posts, checked that it did not cause warnings for blocks where the size had not been set.
For posts where the size had been set, check that the size was correctly converted to em
Types of changes
New feature, potential change to existing posts that have pixel sizes set.
Checklist: