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

ActionList.GroupHeading roll out improvements #4395

Merged
merged 9 commits into from
Mar 27, 2024

Conversation

broccolinisoup
Copy link
Member

@broccolinisoup broccolinisoup commented Mar 15, 2024

Changelog

New

  1. Adds a @deprecated TS notice to the title prop on ActionList.Group sub component.
  2. Adds an invariant check for cases where the action list is rendered as menu or listbox but as prop is provided on the ActionList.GroupHeading component. This is not needed and in fact it could be misleading. Because action lists whose roles are menu or listbox, will render their group headings are divs, not actual headings. (Reefer to the api docs for this accessibility info for now.)
<ActionList role= "menu">
  <ActionList.Group>
    <ActionList.GroupHeading as="h2"><ActionList.GroupHeading> //👈 `as` is not needed here and it is misleading. 
  </ActionList.Group>
</ActionList>

Changed

  1. Update the warning to become error (invariant) for missing as prop on <ActionList.GroupHeading> for list role action lists.
<ActionList>
  <ActionList.Group>
    <ActionList.GroupHeading as="h2"><ActionList.GroupHeading> //  👈 `as` is necessary here to explicitly set the heading level
  </ActionList.Group>
</ActionList>
  1. Update the title prop on ActionList.GroupHeading to _internalBackwardCompatibleTitle, because it is used for to distinguish the old api vs new api for backwards compatibility and we don't want consumers to mistake and use that instead of children. https://github.com/primer/react/pull/4395/files#r1533123778

Removed

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

Merge checklist

Copy link

changeset-bot bot commented Mar 15, 2024

🦋 Changeset detected

Latest commit: e6a19bc

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 Minor

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

Copy link
Contributor

github-actions bot commented Mar 15, 2024

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 88.68 KB (+0.01% 🔺)
packages/react/dist/browser.umd.js 88.98 KB (+0.05% 🔺)

@github-actions github-actions bot temporarily deployed to storybook-preview-4395 March 15, 2024 00:24 Inactive
@@ -85,8 +85,10 @@ export const Group: React.FC<React.PropsWithChildren<ActionListGroupProps>> = ({
>
<GroupContext.Provider value={{selectionVariant, groupHeadingId}}>
{title && !slots.groupHeading ? (
<GroupHeading title={title} variant={variant} auxiliaryText={auxiliaryText} />
// Escape hatch: supports old API <ActionList.Group title="group title"> in a non breaking way
<GroupHeading variant={variant} auxiliaryText={auxiliaryText} unsafeTitle={title} />
Copy link
Member Author

Choose a reason for hiding this comment

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

To make sure that the invariant check doesn't go through on the old API so that it doesn't break any usecases in downstream repos, I kept the ActionList.GroupHeading sub component's API flexible. Especially, to distinguish where the group heading is coming from i.e. old api vs new api.

If it comes from old api (i.e. if it has title prop), I render the heading like

<GroupHeading variant={variant} auxiliaryText={auxiliaryText} title={title} />

if it uses the new api (if children exists),

<GroupHeading variant={variant} auxiliaryText={auxiliaryText} >{title}</GroupHeading>

Copy link
Member

@siddharthkp siddharthkp Mar 25, 2024

Choose a reason for hiding this comment

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

Optional name idea, instead of unsafeTitle: internalBackwardCompatibleTitle

@broccolinisoup broccolinisoup marked this pull request as ready for review March 21, 2024 01:33
@broccolinisoup broccolinisoup requested a review from a team as a code owner March 21, 2024 01:33
@github-actions github-actions bot temporarily deployed to storybook-preview-4395 March 21, 2024 01:37 Inactive
@@ -262,8 +262,8 @@ describe('ActionList', () => {
expect(heading).toBeInTheDocument()
expect(heading).toHaveTextContent('Group Heading')
})
it('should throw a warning if ActionList.Group is used without as prop when no role is specified (for list role)', async () => {
const spy = jest.spyOn(console, 'warn').mockImplementationOnce(() => {})
it('should throw an error if ActionList.GroupHeading is used without an `as` prop when no role is specified (for list role)', async () => {
Copy link
Member Author

@broccolinisoup broccolinisoup Mar 21, 2024

Choose a reason for hiding this comment

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

This test fails https://github.com/primer/react/actions/runs/8368326991/job/22912262706?pr=4395 and I am so confused why - it is throwing an error and I am expecting the error in the test 🤷🏻‍♀️ Am I missing something obvious?

Copy link
Member

Choose a reason for hiding this comment

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

I think you have to explicitly expect it to throw instead of spy

example in primer: https://github.com/primer/react/blob/main/packages/react/src/__tests__/Autocomplete.test.tsx#L444
stack overflow: https://stackoverflow.com/a/46155381

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahh, right! it did the trick, thanks so much 🙌🏻

@@ -73,7 +74,8 @@ export const WithVisualListHeading = () => (
</ActionList.Item>
</ActionList.Group>

<ActionList.Group title="Advanced">
<ActionList.Group>
<ActionList.GroupHeading as="h4">Advanced</ActionList.GroupHeading>
Copy link
Member

Choose a reason for hiding this comment

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

Just checking, do we have a story that still uses the old API? Just to keep it around for regressions

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes! I added them as dev stories https://github.com/primer/react/blob/main/packages/react/src/ActionList/ActionList.dev.stories.tsx and playwright snapshots them too to catch any regression 😈

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.

Looking good! 🎉

Waiting for the tests first before approving!

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.

Looking great! Ship it!

@broccolinisoup broccolinisoup added this pull request to the merge queue Mar 27, 2024
Merged via the queue into main with commit c2557d1 Mar 27, 2024
31 checks passed
@broccolinisoup broccolinisoup deleted the actionlist-group-heading-inprovements branch March 27, 2024 23:09
@primer primer bot mentioned this pull request Mar 27, 2024
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