这是indexloc提供的服务,不要输入任何密码
Skip to content

Refactor h1 and h2 to use Typography component where relevant. #11037

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

Merged

Conversation

benbowler
Copy link
Collaborator

@benbowler benbowler commented Jul 1, 2025

Summary

Addresses issue:

Relevant technical choices

I had to make a few decisions here to refactor title appropriately extending on the IB.

Firstly, I did not refactor the following:

  • h1

  • h2

    • A few uses within tests, factories, and stories.
    • PHP side h2 tags - the Available Tools header and SiwG settings header.

I found that the following titles used h2 tags but using the googlesitekit-heading-3 class so these should be refactored to the h3 style typography component as part of this ticket:

  • assets/js/components/legacy-setup/search-console.js
  • assets/js/components/legacy-setup/site-verification.js
  • assets/js/modules/ads/components/setup/SetupMain.js
  • assets/js/modules/ads/components/setup/SetupMainPAX.js
  • assets/js/modules/adsense/components/common/AdSenseConnectCTA/Content.js
  • assets/js/modules/adsense/components/setup/SetupMain.js
  • assets/js/modules/analytics-4/components/setup/SetupMain.js
  • assets/js/modules/reader-revenue-manager/components/setup/SetupMain.js
  • assets/js/modules/sign-in-with-google/components/setup/SetupMain.js

I did this by setting these to size=small and as='h3'.


Other changes:

  • I changed the PageHeader to use the small header as this fits the previous designs better.

PR Author Checklist

  • My code is tested and passes existing unit tests.
  • My code has an appropriate set of unit tests which all pass.
  • My code is backward-compatible with WordPress 5.2 and PHP 7.4.
  • My code follows the WordPress coding standards.
  • My code has proper inline documentation.
  • I have added a QA Brief on the issue linked above.
  • I have signed the Contributor License Agreement (see https://cla.developers.google.com/).

Do not alter or remove anything below. The following sections will be managed by moderators only.

Code Reviewer Checklist

  • Run the code.
  • Ensure the acceptance criteria are satisfied.
  • Reassess the implementation with the IB.
  • Ensure no unrelated changes are included.
  • Ensure CI checks pass.
  • Check Storybook where applicable.
  • Ensure there is a QA Brief.
  • Ensure there are no unexpected significant changes to file sizes.

Merge Reviewer Checklist

  • Ensure the PR has the correct target branch.
  • Double-check that the PR is okay to be merged.
  • Ensure the corresponding issue has a ZenHub release assigned.
  • Add a changelog message to the issue.

Copy link

github-actions bot commented Jul 1, 2025

Build files for cc0abb5 have been deleted.

Copy link

github-actions bot commented Jul 1, 2025

Size Change: +4.91 kB (+0.22%)

Total Size: 2.22 MB

ℹ️ View Unchanged
Filename Size Change
./dist/assets/css/googlesitekit-admin-css-********************.min.css 63.6 kB -62 B (-0.1%)
./dist/assets/css/googlesitekit-adminbar-css-********************.min.css 11.8 kB -29 B (-0.25%)
./dist/assets/css/googlesitekit-authorize-application-css-********************.min.css 846 B 0 B
./dist/assets/css/googlesitekit-wp-dashboard-css-********************.min.css 8.44 kB 0 B
./dist/assets/js/32-********************.js 2.76 kB 0 B
./dist/assets/js/33-********************.js 2.25 kB 0 B
./dist/assets/js/34-********************.js 3.64 kB 0 B
./dist/assets/js/35-********************.js 936 B 0 B
./dist/assets/js/36-********************.js 893 B 0 B
./dist/assets/js/37-********************.js 1.83 kB +1 B (+0.05%)
./dist/assets/js/38-********************.js 3.12 kB 0 B
./dist/assets/js/analytics-advanced-tracking-********************.js 903 B 0 B
./dist/assets/js/blocks/reader-revenue-manager/block-editor-plugin/editor-styles.css 124 B 0 B
./dist/assets/js/blocks/reader-revenue-manager/block-editor-plugin/editor-styles.js 491 B 0 B
./dist/assets/js/blocks/reader-revenue-manager/block-editor-plugin/index.js 47.1 kB 0 B
./dist/assets/js/blocks/reader-revenue-manager/common/editor-styles.css 307 B 0 B
./dist/assets/js/blocks/reader-revenue-manager/common/editor-styles.js 492 B 0 B
./dist/assets/js/blocks/reader-revenue-manager/contribute-with-google/index.js 9.5 kB 0 B
./dist/assets/js/blocks/reader-revenue-manager/contribute-with-google/non-site-kit-user.js 8.99 kB 0 B
./dist/assets/js/blocks/reader-revenue-manager/subscribe-with-google/index.js 9.5 kB 0 B
./dist/assets/js/blocks/reader-revenue-manager/subscribe-with-google/non-site-kit-user.js 8.99 kB 0 B
./dist/assets/js/blocks/sign-in-with-google/editor-styles.css 84 B 0 B
./dist/assets/js/blocks/sign-in-with-google/editor-styles.js 492 B 0 B
./dist/assets/js/blocks/sign-in-with-google/index.js 18.1 kB 0 B
./dist/assets/js/googlesitekit-activation-********************.js 24.9 kB +207 B (+0.84%)
./dist/assets/js/googlesitekit-ad-blocking-recovery-********************.js 63.7 kB +338 B (+0.53%)
./dist/assets/js/googlesitekit-adminbar-********************.js 37.7 kB +83 B (+0.22%)
./dist/assets/js/googlesitekit-api-********************.js 10.4 kB 0 B
./dist/assets/js/googlesitekit-components-********************.js 6.8 kB +4 B (+0.06%)
./dist/assets/js/googlesitekit-consent-mode-********************.js 25.6 kB 0 B
./dist/assets/js/googlesitekit-data-********************.js 2.37 kB -3 B (-0.13%)
./dist/assets/js/googlesitekit-datastore-forms-********************.js 9.12 kB +3 B (+0.03%)
./dist/assets/js/googlesitekit-datastore-location-********************.js 2.09 kB +2 B (+0.1%)
./dist/assets/js/googlesitekit-datastore-site-********************.js 20.7 kB -6 B (-0.03%)
./dist/assets/js/googlesitekit-datastore-ui-********************.js 9.26 kB +5 B (+0.05%)
./dist/assets/js/googlesitekit-datastore-user-********************.js 27 kB -37 B (-0.14%)
./dist/assets/js/googlesitekit-entity-dashboard-********************.js 66.8 kB +377 B (+0.57%)
./dist/assets/js/googlesitekit-events-provider-contact-form-7-********************.js 646 B 0 B
./dist/assets/js/googlesitekit-events-provider-easy-digital-downloads-********************.js 977 B 0 B
./dist/assets/js/googlesitekit-events-provider-mailchimp-********************.js 630 B 0 B
./dist/assets/js/googlesitekit-events-provider-ninja-forms-********************.js 717 B 0 B
./dist/assets/js/googlesitekit-events-provider-optin-monster-********************.js 675 B 0 B
./dist/assets/js/googlesitekit-events-provider-popup-maker-********************.js 639 B 0 B
./dist/assets/js/googlesitekit-events-provider-woocommerce-********************.js 1.39 kB 0 B
./dist/assets/js/googlesitekit-events-provider-wpforms-********************.js 633 B 0 B
./dist/assets/js/googlesitekit-i18n-********************.js 4.16 kB 0 B
./dist/assets/js/googlesitekit-main-dashboard-********************.js 147 kB +213 B (+0.15%)
./dist/assets/js/googlesitekit-metric-selection-********************.js 61.5 kB +272 B (+0.44%)
./dist/assets/js/googlesitekit-modules-********************.js 24 kB +15 B (+0.06%)
./dist/assets/js/googlesitekit-modules-ads-********************.js 53.6 kB +170 B (+0.32%)
./dist/assets/js/googlesitekit-modules-adsense-********************.js 136 kB +286 B (+0.21%)
./dist/assets/js/googlesitekit-modules-analytics-4-********************.js 213 kB +257 B (+0.12%)
./dist/assets/js/googlesitekit-modules-pagespeed-insights-********************.js 26.6 kB 0 B
./dist/assets/js/googlesitekit-modules-reader-revenue-manager-********************.js 49.4 kB +325 B (+0.66%)
./dist/assets/js/googlesitekit-modules-search-console-********************.js 75.5 kB +245 B (+0.33%)
./dist/assets/js/googlesitekit-modules-sign-in-with-google-********************.js 36.8 kB +193 B (+0.53%)
./dist/assets/js/googlesitekit-modules-tagmanager-********************.js 33.4 kB +187 B (+0.56%)
./dist/assets/js/googlesitekit-notifications-********************.js 69.7 kB +326 B (+0.47%)
./dist/assets/js/googlesitekit-polyfills-********************.js 376 B 0 B
./dist/assets/js/googlesitekit-settings-********************.js 141 kB +240 B (+0.17%)
./dist/assets/js/googlesitekit-splash-********************.js 80.5 kB +227 B (+0.28%)
./dist/assets/js/googlesitekit-user-input-********************.js 54.3 kB +274 B (+0.51%)
./dist/assets/js/googlesitekit-vendor-********************.js 314 kB +395 B (+0.13%)
./dist/assets/js/googlesitekit-widgets-********************.js 113 kB +179 B (+0.16%)
./dist/assets/js/googlesitekit-wp-dashboard-********************.js 66 kB +220 B (+0.33%)
./dist/assets/js/runtime-********************.js 1.32 kB -2 B (-0.15%)

compressed-size-action

Copy link
Collaborator

@zutigrm zutigrm left a comment

Choose a reason for hiding this comment

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

Thanks @benbowler, usage of the Typography component is almost there, but it seems there is an implementation part that has been missed from the IB

Search for <h1 and <h2 across the codebase and replace it by using Typography component, and passing as prop with value of h1 and h2 respectively

Mainly the "passing as prop with value of h1 and h2 respectively". We should use as prop to mark the heading tags correctly, for h1 would be <Typography as="h1" {...}>{...}</Typography> etc.

You can see example of a full usage in the stories file

<Typography as="h1" size="large" type="display">
Typography
</Typography>

Let's include the missing prop to the implemented Typography components

As to the regard of not replacing headings with Typography in the stories and tests, not sure there is a specific reason we would omit it there, as referenced above, this is already implemented in the Typography.stories.js file. We should replace usage of hardcoded headings completely with the Typography file in the JS files (components, jest tests, storybook stories)

Copy link
Collaborator

@zutigrm zutigrm left a comment

Choose a reason for hiding this comment

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

Thanks @benbowler looks much better. Just one more thing to check

@benbowler
Copy link
Collaborator Author

Note that E2E tests started failing consistently here, not sure why because the changes are unrelated, however I added timeouts to allow the tests/e2e/specs/user-input-questions.test.js tests to pass consistently local and on CI.

Copy link
Collaborator

@zutigrm zutigrm left a comment

Choose a reason for hiding this comment

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

Thanks @benbowler LGTM

Copy link
Collaborator

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

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

Just a few questions here, but looks good 👍🏻

Comment on lines -155 to +161
<h2 className="googlesitekit-heading-3 googlesitekit-setup-module__title">
<Typography
as="h3"
className="googlesitekit-setup-module__title"
size="small"
type="headline"
>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why the change in heading hierarchy here? This used to be an <h2>.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is because it was an h2 with the class googlesitekit-heading-3 - I suppose we could keep as="h2" but the other props as "small" / "headine" to style like it should be. Does that make more sense?

There were a few like this in the codebase where h2s were styled as h3s.

@@ -13,7 +13,7 @@ exports[`AdminMenuTooltip should render when isTooltipVisible is true and track
class="googlesitekit-tooltip-body"
>
<h2
class="googlesitekit-tooltip-title"
class="googlesitekit-typography googlesitekit-tooltip-title googlesitekit-typography--title googlesitekit-typography--medium"
>
Test Title
</h2>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not use the <Typography> component here too? It would allow us to better test (with snapshots) the output of the component, and might as well use it everywhere we would in production 🤔

Copy link
Collaborator Author

@benbowler benbowler Jul 18, 2025

Choose a reason for hiding this comment

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

This is the snapshot of the Joyride > Step component which does use the Typography component:

<Typography
as="h2"
className="googlesitekit-stepper__step-title"
size="medium"
type="title"
>
{ title }
</Typography>

Copy link
Collaborator

Choose a reason for hiding this comment

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

OMG 🤦🏻

My bad for missing that 😅

Comment on lines -76 to +78
<h2 className="googlesitekit-heading-3 googlesitekit-setup-module__title">
<Typography
as="h3"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why the change here to H3? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As above.

@tofumatt tofumatt merged commit beb4748 into develop Jul 21, 2025
23 checks passed
@tofumatt tofumatt deleted the enhancement/10905-replace-headings-with-typography-component branch July 21, 2025 12:52
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.

3 participants