Skip to content

Conversation

@francinen
Copy link
Contributor

@francinen francinen commented Oct 9, 2020

WHY are these changes introduced?

Fixes #3414

When the new design language is enabled, the page title shrinks when the Skeleton Page component is replaced by the Page component.

Kapture 2020-10-07 at 14 08 22

The font size for the page title should be consistent between the Skeleton Page component and the Page component.

WHAT is this pull request doing?

This PR implements a solution similar to the one introduced by #3468. Instead of using JavaScript to conditionally render small or large Display Text when the navigation is collapsed, the Skeleton Page component now relies purely on CSS to set different font sizes based on specific breakpoints.

New design language Current design language (no regressions)
page-title-skeleton-after page-title-skeleton-prev-design-lang

How to 🎩

🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines

Testing in Storybook

  1. Run dev s in the Polaris React repo to open Storybook
  2. Look at the Skeleton Page examples and ensure there are no regressions
Page title defined Page title undefined
image image

Testing against a Shopify Web

  1. Check out this branch and configure Shopify Web to consume your local Polaris React repo
  2. Visit a page that uses the Skeleton Page component (e.g., /admin/apps, /admin/products, /admin/dashboards)
Viewport width Page title defined Page title undefined
Mobile skeleton-page-title-defined-mobile skeleton-page-title-null-mobile
Desktop skeleton-page-title-defined-wide skeleton-page-title-null-wide

🎩 checklist

  • Tested on mobile
  • Tested on multiple browsers
  • Tested for accessibility
  • Updated the component's README.md with documentation changes
  • Tophatted documentation changes in the style guide
  • For visual design changes, pinged one of @ HYPD, @ mirualves, @ sarahill, or @ ry5n to update the Polaris UI kit

@github-actions
Copy link
Contributor

github-actions bot commented Oct 9, 2020

🟢 This pull request modifies 4 files and might impact 1 other files.

Details:
All files potentially affected (total: 1)
📄 UNRELEASED.md (total: 0)

Files potentially affected (total: 0)

🎨 src/components/SkeletonPage/SkeletonPage.scss (total: 1)

Files potentially affected (total: 1)

🧩 src/components/SkeletonPage/SkeletonPage.tsx (total: 0)

Files potentially affected (total: 0)

🧩 src/components/SkeletonPage/tests/SkeletonPage.test.tsx (total: 0)

Files potentially affected (total: 0)

@francinen francinen requested a review from kyledurand October 9, 2020 17:51
@francinen
Copy link
Contributor Author

Does anyone know why small Display Text is being rendered when the navigation is collapsed, even though we're passing in "large" as the size prop?

image

image

cc @kyledurand

@francinen francinen changed the title [new DL][Skeleton Page] Ensure skeleton page title is the same font size as title rendered in Page component [new DL][Skeleton Page] Ensure Skeleton Page title is the same font size as title rendered in Page component Oct 9, 2020
@kyledurand
Copy link
Member

kyledurand commented Oct 9, 2020

Does anyone know why small Display Text is being rendered when the navigation is collapsed

I wonder if this is because the media query provider doesn't yet know the size of the viewport. @BPScott would probably know the answer for sure.

Ben could this be caused by SSR? @francinen does this ever get display text large when the nav is collapsed? Or does it flash small and then switch to large?

@francinen
Copy link
Contributor Author

@kyledurand When the navigation is collapsed, the display text switches from small to large as the Skeleton Page is replaced by the Page component.

@BPScott
Copy link
Member

BPScott commented Oct 9, 2020

I wonder if this is because the media query provider doesn't yet know the size of the viewport. @BPScott would probably know the answer for sure.
Ben could this be caused by SSR? @francinen does this ever get display text large when the nav is collapsed? Or does it flash small and then switch to large?

Yeah this sounds right to me. When the HTML is rendered on the server-side it doesn't doesn't have any concept of media-queries or window.matchMedia (or even window!). You're using {isNavigationCollapsed} = useMediaQuery(), taking a look at MediaQueryProvider and following that into breakpoints.tsx we see that sets isNavigationCollapsed based on a media query, and on the server where no window.matchMedia is available it looks like it defaults to returning "false" - same as on a large screen (>768px) in a browser.

If our aim here is to match what the Page Header Title component does then it looks like we're good as that uses useMediaQuery to toggle the size of the DisplayText too. But there might be a better way (depending on how much effort you want to put in here)...

To get up on a pedestal for a moment: IMO MediaQueryProvider is an anti-pattern because it causes issues like this where there ends up being html mismatches between the client and the server. Changing html content based upon browser width has the potential to make the browser do lots of work and we should trry to avoid it where possible, instead we should rely on good old CSS, and where feasible always render the same HTML but show/hide it with CSS media queries.

Ideally instead of doing <DisplayText size={newDesignLanguage ? (displaySize = isNavigationCollapsed ? 'large' : 'small') : 'large'}> in both Page Header Title and in SkeletonPage we should create a new css class and style it with our scss mixins, so that we don't need to use useMedia() at all. Something like the following (typed but not tested) in Title:

.TitleText {
  @include text-style-display-large;

  .newDesignLanguage  {
    @include frame-when-nav-displayed {
      @include text-style-display-small;
  }
}

and then something similar in SkeletonPage to mimic those box heights.

@francinen
Copy link
Contributor Author

@BPScott The CSS approach sounds a lot more scalable. I can give that a try later today. Thank you!

@BPScott
Copy link
Member

BPScott commented Oct 13, 2020

Related: #3468.

Looks like that's ended up with a similar approach to what I talked about above (though it seems the breakpoint we want to use has changed)

@francinen francinen force-pushed the skeleton-page-title-fix-font-size branch 4 times, most recently from 9bfa34f to ff48392 Compare October 14, 2020 18:11
@francinen francinen marked this pull request as ready for review October 14, 2020 18:11
@francinen francinen requested a review from BPScott October 14, 2020 18:11
@francinen
Copy link
Contributor Author

@kyledurand @BPScott This PR is officially ready for review

@francinen francinen force-pushed the skeleton-page-title-fix-font-size branch 2 times, most recently from 1fc6369 to 3a4adb8 Compare October 14, 2020 18:17
@francinen francinen requested a review from alex-page October 14, 2020 18:17
return <div className={styles.Title}>{titleContent}</div>;
}

return <SkeletonDisplayText size="large" />;
Copy link
Member

@BPScott BPScott Oct 14, 2020

Choose a reason for hiding this comment

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

Does this <SkeletonDisplayText size="large"> have the same visual height as the new design language title at all viewport sizes?

I've not confirmed this but I'm guessing it doesn't as <DisplayText size="large"> matches <SkeletonDisplayText size="large"> and @alex-page wrote custom css instead of using <DisplayText size="large"> in Page. (Alternatively <SkeletonDisplayText size="large"> and thus <DisplayText size="large"> matches the new header css in Page in which case we should just use DisplayText instead of writing custom css in Page)

We should make sure this Skeleton content is the same height so we don't trigger layout shifts here too.

Copy link
Member

Choose a reason for hiding this comment

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

I have the same concern too, it looks like this change would only match what we have in Title if the title was passed in to skeleton page. Otherwise you'd always be getting display text which I don't think matches perfectly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some of the gifs added to the PR description show the transition from Skeleton Display Text to Display Text:

skeleton-page-title-null-mobile

skeleton-page-title-null-wide

Copy link
Member

Choose a reason for hiding this comment

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

Looks like <SkeletonDisplayText size="large"> uses the display-large line heights for its heights - 28px base, 32px when-typography-not-condensed, while Page title / newDesignLanguageTitle uses 28px at all sizes) so these are indeed different.

That looks about right with the jump seen in those gifs.

Would you be interested in fixing this up so the Skeleton height matches real content so we don't get page jumps there? (uugh it looks like we currently get a jump in that first gif because the actions are taller than the title but that feels slightly out of scope for this ticket).

A div with a class like this should do the job (written but not tested):

// duplicated from SkeletonDisplayText.scss
$skeleton-display-text-max-width: rem(120px);

.newDesignLanguageSkeletonTitle {
  @include skeleton-shimmer;
  @include skeleton-content;

  max-width: $skeleton-display-text-max-width;
  height: rem(28px);
}

@francinen francinen force-pushed the skeleton-page-title-fix-font-size branch from 3a4adb8 to 53cb7f8 Compare October 16, 2020 17:35
@francinen francinen requested a review from BPScott October 16, 2020 17:35
@francinen francinen force-pushed the skeleton-page-title-fix-font-size branch from 53cb7f8 to d0b22b9 Compare October 16, 2020 18:07
@francinen
Copy link
Contributor Author

@BPScott or @kyledurand Are either of you able to re-review this PR? I responded to the question re: the Skeleton Display Text height here: #3449 (comment)

Copy link
Member

@kyledurand kyledurand left a comment

Choose a reason for hiding this comment

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

Code looks good 👍

Looks like there might still be some content jumpiness in the second gif but this is definitely a solid improvement 👏

Thanks @francinen

Copy link
Member

@BPScott BPScott left a comment

Choose a reason for hiding this comment

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

Add a comment inline about Skeleton heights with a possible solution.

@kyledurand / @alex-page: Any strong thoughts on if this should be done in this PR or if this can be done in a separate PR?

return <div className={styles.Title}>{titleContent}</div>;
}

return <SkeletonDisplayText size="large" />;
Copy link
Member

Choose a reason for hiding this comment

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

Looks like <SkeletonDisplayText size="large"> uses the display-large line heights for its heights - 28px base, 32px when-typography-not-condensed, while Page title / newDesignLanguageTitle uses 28px at all sizes) so these are indeed different.

That looks about right with the jump seen in those gifs.

Would you be interested in fixing this up so the Skeleton height matches real content so we don't get page jumps there? (uugh it looks like we currently get a jump in that first gif because the actions are taller than the title but that feels slightly out of scope for this ticket).

A div with a class like this should do the job (written but not tested):

// duplicated from SkeletonDisplayText.scss
$skeleton-display-text-max-width: rem(120px);

.newDesignLanguageSkeletonTitle {
  @include skeleton-shimmer;
  @include skeleton-content;

  max-width: $skeleton-display-text-max-width;
  height: rem(28px);
}

@francinen francinen force-pushed the skeleton-page-title-fix-font-size branch from d0b22b9 to c716f00 Compare October 26, 2020 14:48
@francinen
Copy link
Contributor Author

Thanks, @BPScott! How does this look?

skeleton-title

@francinen francinen requested a review from BPScott October 26, 2020 14:49
@francinen francinen force-pushed the skeleton-page-title-fix-font-size branch from c716f00 to d09d172 Compare October 26, 2020 15:16
Copy link
Member

@alex-page alex-page left a comment

Choose a reason for hiding this comment

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

This looks good to me. @BPScott @kyledurand anything stopping us from merging?

@kyledurand
Copy link
Member

Nope 🚢 !

@BPScott
Copy link
Member

BPScott commented Oct 28, 2020

There's still a bit of a vertical jump (note the top bar of skeleton tab bar in the gif) but i think that's from the action buttons being taller than the title text now, which feels like a separate issue. Happy to 🚢 as is! Thanks for putting up with us @francinen!

@alex-page alex-page merged commit 0feaf8c into master Oct 28, 2020
@alex-page alex-page deleted the skeleton-page-title-fix-font-size branch October 28, 2020 20:32
sylvhama pushed a commit that referenced this pull request Mar 26, 2021
…en new design language is enabled (#3449)

Co-authored-by: Alex Page <alex@alexpage.com.au>
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.

Text size of skeleton content should match page component

4 participants