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

amp-fit-text:1.0 Vertical center non-overflowing text #32558

Merged
merged 4 commits into from
Feb 10, 2021

Conversation

caroqliu
Copy link
Contributor

@caroqliu caroqliu commented Feb 9, 2021

Prior to this change, the following markup would show these version differences in vertical centering for non-overflowing text:

0.1 1.0
image image

This PR applies flex-direction: column, justify-contents: center to the text container in amp-fit-text, and conditionally applies display: flex to make the prior styles effective when there is not overflow, so that the text can be vertically centered within its measuring container, which in turn is already vertically centered within its outer container. Two important notes when there is overflow:

  • We do not want text itself to be vertically centered with respect to its measuring container when there is overflow, as this would clip the beginning of the text.
  • We do want the measuring container to be vertically centered with respect to its outer container, which is already the case.

Related to #28281

@@ -34,7 +34,7 @@ export const _default = () => {
<FitText
minFontSize={minFontSize}
maxFontSize={maxFontSize}
style={{display: 'block', border: '1px solid black', width, height}}
style={{border: '1px solid black', width, height}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it matter here if display:block is set? Does it go on a wrapper or a content element?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, unfortunately it depends also whether there is overflowing text. display: block here will undo centering when there is overflowing tex (which it was doing here already), but not when there is not overflowing text (which gets vertically centered within the intermediary <div>). I guess one option is we that the middle element could take the display value from the parent element so it will impact both? But it is not intuitive.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need an extra wrapper then. I think it'd be very natural for someone to want to style this element with display: inline-block or similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To clarify: You want an extra wrapper so that setting display does not impact any form of internal centering?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it not suffice to encourage folks to use inline-flex? Or is the intent to stabilize the unexpected centering behavior if they do use inline-block?

Copy link
Contributor

Choose a reason for hiding this comment

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

That seems pretty fragile and leaks some implementation details. If we can isolate, that'd work better, imho. E.g. centering with flexbox is one way (and maybe the best way at this time). But there could be other possibilities as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a wrapper as suggested.

{children}
</div>
</ContainWrapper>
<Wrapper {...rest}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Any way to reverse these wrappers? It'd be very good to have contain: size layout paint on the top wrapper.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants