-
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
Changes from all commits
cbcd7b5
86823a3
f94e8d2
9b21aa0
5dc9a53
8eabc6e
4f154cf
114cac6
e6a19bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@primer/react": minor | ||
--- | ||
ActionList.Group: deprecate `title` prop - please use `ActionList.GroupHeading` instead | ||
ActionList.GroupHeading: update the warning to be an error if there is no explict `as` prop for list `role` action lists. | ||
ActionList.GroupHeading: There shouldn't be an `as` prop on `ActionList.GroupHeading` for `listbox` or `menu` role action lists. console.error if there is one |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -249,6 +249,35 @@ describe('ActionList', () => { | |
expect(spy).toHaveBeenCalled() | ||
spy.mockRestore() | ||
}) | ||
|
||
it('should throw an error when ActionList.GroupHeading has an `as` prop when it is used within ActionMenu context', async () => { | ||
const spy = jest.spyOn(console, 'error').mockImplementation(() => jest.fn()) | ||
expect(() => | ||
HTMLRender( | ||
<ThemeProvider theme={theme}> | ||
<SSRProvider> | ||
<BaseStyles> | ||
<ActionMenu open={true}> | ||
<ActionMenu.Button>Trigger</ActionMenu.Button> | ||
<ActionMenu.Overlay> | ||
<ActionList> | ||
<ActionList.Group> | ||
<ActionList.GroupHeading as="h2">Group Heading</ActionList.GroupHeading> | ||
</ActionList.Group> | ||
</ActionList> | ||
</ActionMenu.Overlay> | ||
</ActionMenu> | ||
</BaseStyles> | ||
</SSRProvider> | ||
</ThemeProvider>, | ||
), | ||
).toThrow( | ||
"Looks like you are trying to set a heading level to a menu role. Group headings for menu type action lists are for representational purposes, and rendered as divs. Therefore they don't need a heading level.", | ||
) | ||
expect(spy).toHaveBeenCalled() | ||
spy.mockRestore() | ||
}) | ||
|
||
it('should render the ActionList.GroupHeading component as a heading with the given heading level', async () => { | ||
const container = HTMLRender( | ||
<ActionList> | ||
|
@@ -262,18 +291,22 @@ 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(() => {}) | ||
|
||
HTMLRender( | ||
<ActionList> | ||
<ActionList.Heading as="h1">Heading</ActionList.Heading> | ||
<ActionList.Group> | ||
<ActionList.GroupHeading>Group Heading</ActionList.GroupHeading> | ||
</ActionList.Group> | ||
</ActionList>, | ||
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 commentThe 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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh, right! it did the trick, thanks so much 🙌🏻 |
||
const spy = jest.spyOn(console, 'error').mockImplementation(() => jest.fn()) | ||
expect(() => | ||
HTMLRender( | ||
<ActionList> | ||
<ActionList.Heading as="h1">Heading</ActionList.Heading> | ||
<ActionList.Group> | ||
<ActionList.GroupHeading>Group Heading</ActionList.GroupHeading> | ||
<ActionList.Item>Item</ActionList.Item> | ||
</ActionList.Group> | ||
</ActionList>, | ||
), | ||
).toThrow( | ||
"You are setting a heading for a list, that requires a heading level. Please use 'as' prop to set a proper heading level.", | ||
) | ||
expect(spy).toHaveBeenCalledTimes(1) | ||
expect(spy).toHaveBeenCalled() | ||
spy.mockRestore() | ||
}) | ||
it('should render the ActionList.GroupHeading component as a span (not a heading tag) when role is specified as listbox', 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.
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 😈