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

USWDS - Documentation page: Improve backwards compatibility with sidenav order #5809

Merged
merged 6 commits into from Mar 11, 2024

Conversation

mejiaj
Copy link
Contributor

@mejiaj mejiaj commented Mar 8, 2024

Summary

Introduced a fallback for Documentation sidenav changes. A new setting $theme-sidenav-reorder allows users to reorder the sidenav to avoid visual regressions.

Caution

Setting $theme-sidenav-reorder: true has a negative impact on users of assistive technologies.

Breaking change

This is not a breaking change.

Related issue

Closes #5807.

Related pull requests

Changelog entry added to uswds/uswds-site#2495.

Preview link

Preview link: Test Documentation Reorder ⋅ Storybook

Problem statement

Without a fallback, users who update to 3.8.0 will have to update all their templates to follow new guidance. This new setting allows for incremental adoption towards this new recommendation.

Solution

This pull request adds a new component theme setting for those who are unable to make that change right now. You can do that by setting $theme-sidenav-reorder: true in theme settings.

This will give you a warning on compile and suggesting the new recommendation above.

New recommendation from #5794

#5794 introduced a potentially breaking change that requires a markup update. We recommend including a duplicate sidenav and toggling visibility based on breakpoints.

Include a duplicate sidenav and ensure the utility classes are correct. The example below shows a before/after.

<div class="grid-container">
  <div class="grid-row grid-gap">
-   <div class="usa-layout-docs__sidenav">
+   <!-- One of two sidenav's only shown in desktop breakpoints. --> 
+   <div class="usa-layout-docs__sidenav display-none desktop:display-block desktop:grid-col-3">
      {{ SIDENAV_MARKUP }}
    </div>
-   <main class="usa-layout-docs__main desktop:grid-col-9 usa-prose usa-layout-docs" id="main-content">
+   <main class="desktop:grid-col-9 usa-prose usa-layout-docs" id="main-content">
      {{ MAIN_CONTENT }}
    </main>
  </div>
+ <!-- New duplicate section only shown on mobile. -->
+  <div class="usa-layout-docs__sidenav desktop:display-none">
+    {{ SIDENAV_MARKUP }}
+  </div>
</div>

Approach

Possible limitations

The desktop breakpoint in _usa-layout-docs.scss:20 is fixed and users don't have an easy way of overriding this.

@include at-media("desktop") {
@include grid-col(3);
order: 0;
}

Major changes

  • New component theme setting $theme-sidenav-reorder: false !default.
  • New test story & storybook control

Testing and review

There's a new test story that allow you to toggle and compare behaviors. Toggle Reorder with CSS to test old behavior.

Testing checklist

  • Zero regressions in HTML output - npm run build:html.
  • Documentation page by default has two sidenavs that toggle display based on breakpoint.
  • Documentation page test can revert to old behavior on TRUE via StorybookJS control.
  • New reorder setting in _settings-components.scss.
  • New setting is FALSE by default.
  • New setting reorders sidenav on TRUE and provides a warning on compile.

Todo

  • Write SASS notification

mejiaj added a commit to uswds/uswds-site that referenced this pull request Mar 8, 2024
@mejiaj mejiaj marked this pull request as ready for review March 8, 2024 19:27
@mejiaj mejiaj requested a review from thisisdano March 8, 2024 19:27
@mejiaj mejiaj requested a review from mahoneycm March 11, 2024 13:53
Copy link
Contributor

@mahoneycm mahoneycm left a comment

Choose a reason for hiding this comment

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

Loving this fix! Adds great flexibility to our users.

Testing checklist

  • Zero regressions in HTML output - npm run build:html.
  • Documentation page by default has two sidenavs that toggle display based on breakpoint.
    • Inspecting markup shows nav elements before main
  • Documentation page test can revert to old behavior on TRUE via StorybookJS control.
  • New reorder setting in _settings-components.scss.
  • New setting is FALSE by default.
  • New setting reorders sidenav on TRUE and provides a warning on compile.
  • Installing and testing on sandbox works as expected
    • Warning on compile
    • Sidenav displays correctly using old markup and new setting

Comment on lines +58 to +67
{% if sidenav_reorder %}
<style>
.usa-layout-docs__sidenav {
outline: 1px dashed orange;
}
</style>

Ensure <code>$theme-sidenav-reorder: true</code> in theme settings & in StorybookJS. The sidenav will be placed <em>after</em> main content and a compile warning should display.
{% endif %}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This doesn't display in final HTML build because it's controlled by the StorybookJS control in usa-docs.stories.js.

TestDocumentationReorder.argTypes = {
sidenav_reorder: {
control: { type: "boolean" },
defaultValue: false,
name: "Reorder with CSS",
},
};

Copy link
Member

@thisisdano thisisdano left a comment

Choose a reason for hiding this comment

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

Very nice. Thanks for thinking this through!

@thisisdano thisisdano merged commit 8cb4125 into develop Mar 11, 2024
5 checks passed
@thisisdano thisisdano deleted the jm-feature-doc-layout-order-setting branch March 11, 2024 16:32
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.

USWDS - Documentation: Allow sidenav reorder via settings
3 participants