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

NavList add defaultOpen to NavList.Item #3698

Merged
merged 5 commits into from
Sep 6, 2023
Merged

Conversation

gracepark
Copy link
Contributor

Closes https://github.com/github/primer/issues/2512

This adds the defaultOpen prop to NavList.Item. We needed this because in the Docs sidebar needs the ability to have a NavList.SubNav default to open even without an aria-current in its nested levels like so:

Item 1 is default to open because it has the defaultOpen prop so that sub item 1 is viewable

Another pro is that this essentially resolves depending on client-side rendering of our sidebar.

A few notes about my changes:

  • I named the prop defaultOpen to follow a similar pattern to TreeView's defaultExpanded. We're wondering if it'd be a little more accurate to name it something like initiallyOpen, defaultToOpen or openOnStart.
  • I wanted to catch the possiblity of setting a defaultOpen on a NavList.Item without a NavList.SubNav. I was thinking it could throw an error instead, but I noticed below other checks like depth were using console.error, so I did the same.

Thank you for the review, and please let me know if there are any questions or concerns!

Screenshots

No real visual difference unless a defaultOpen is added to a NavList.Item with a NavList.SubNav. That is shown above in the changes I described.

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Changes are SSR compatible
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.

@gracepark gracepark requested review from a team and siddharthkp September 5, 2023 15:35
@changeset-bot
Copy link

changeset-bot bot commented Sep 5, 2023

🦋 Changeset detected

Latest commit: ad2a14f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Sep 5, 2023

size-limit report 📦

Path Size
dist/browser.esm.js 104.65 KB (+0.07% 🔺)
dist/browser.umd.js 105.21 KB (+0.07% 🔺)

@gracepark gracepark temporarily deployed to github-pages September 5, 2023 15:42 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3698 September 5, 2023 15:43 Inactive
@gracepark gracepark temporarily deployed to github-pages September 5, 2023 15:51 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3698 September 5, 2023 15:51 Inactive
Copy link
Member

@siddharthkp siddharthkp left a comment

Choose a reason for hiding this comment

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

LGTM!

@siddharthkp
Copy link
Member

I named the prop defaultOpen to follow a similar pattern to TreeView's defaultExpanded. We're wondering if it'd be a little more accurate to name it something like initiallyOpen, defaultToOpen or openOnStart

You're completely right, but because the HTML API has keys like defaultValue and defaultChecked, it's pretty common to see the same in the React ecosystem (For example in these docs)

To keep the API familiar, we have kept the same convention for props that set the initial value in primer/react as well

@siddharthkp siddharthkp added this pull request to the merge queue Sep 6, 2023
Merged via the queue into main with commit d759fd3 Sep 6, 2023
30 checks passed
@siddharthkp siddharthkp deleted the navlist-add-defaultOpen branch September 6, 2023 13:30
@primer primer bot mentioned this pull request Sep 6, 2023
@siddharthkp
Copy link
Member

siddharthkp commented Sep 6, 2023

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.

2 participants