-
Notifications
You must be signed in to change notification settings - Fork 538
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
Conversation
🦋 Changeset detectedLatest commit: e6a19bc The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
size-limit report 📦
|
@@ -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} /> |
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
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
@@ -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 () => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 😈
There was a problem hiding this 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!
There was a problem hiding this 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!
Changelog
New
@deprecated
TS notice to thetitle
prop onActionList.Group
sub component.as
prop is provided on theActionList.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.)Changed
warning
to become error (invariant) for missingas
prop on<ActionList.GroupHeading>
forlist
role action lists.title
prop onActionList.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#r1533123778Removed
Rollout strategy
Testing & Reviewing
Merge checklist