-
Notifications
You must be signed in to change notification settings - Fork 536
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
Add ActionList.Heading component #3581
Conversation
🦋 Changeset detectedLatest commit: c68c0cc 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 📦
|
ba37bef
to
7980fe1
Compare
@@ -41,6 +42,109 @@ export const SimpleList = () => ( | |||
</ActionList> | |||
) | |||
|
|||
export const WithHeading = () => ( |
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 we should add this heading to docs and all stories in another PR after this, to show that this is the recommended usage.
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.
Oh that is right! All should have a heading.
We should also update the ActionList
usages in other primer react components , right? 🤔 Like NavList to lead the change
@@ -42,32 +47,42 @@ export const List = React.forwardRef<HTMLUListElement, ActionListProps>( | |||
paddingY: variant === 'inset' ? 2 : 0, | |||
} | |||
|
|||
const [slots, childrenWithoutSlots] = useSlots(props.children, { | |||
heading: Heading, | |||
}) |
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.
Would this already work with eslint-plugin-primer-react or do we need to update that as well?
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 we would need to make some update on the eslint plugin.
- We need to add
ActionList: ['ActionList.Header'],
in this object
Although, this rule will only prevent folks from using ActionList.Heading
outside of ActionList
, this won't warn if the ActionList
is missing ActionList.Heading
which I believe this is something we need as well? Can we do this with the type system at all? 🤔 (This would make the change breaking, though) Or should we look into adding another eslint rule for that too?
Also we can add ActionList.Heading
to the a11y-explicit-heading rule to restrict the values passed to as
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.
Considering action lists in menus shouldn't have a heading (reference), maybe we can enforece this with the eslint rule as well?
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.
Also we can add ActionList.Heading to the a11y-explicit-heading rule to restrict the values passed to as
Because ActionList.Heading is a new component, we can also use typescript to restrict allowed values for as
:)
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.
Considering action lists in menus shouldn't have a heading (#3581 (comment)), maybe we can enforece this with the eslint rule as well?
Good point. We could add an eslint rule for this, however, I'm not sure how effectively we would be able to catch incorrect usage given ActionList does not have to be a direct child of ActionMenu, it can be abstracted in a custom UserList
or BranchList
component that uses ActionList internally.
We also have the option of a dev environment runtime warning. Because we know when an ActionList is contained inside ActionMenu, we could use that to throw a warning
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.
Because ActionList.Heading is a new component, we can also use typescript to restrict allowed values for as :)
That is so true! I missed that 😅 which is already restricted anyway!
We also have the option of a dev environment runtime warning. Because we know when an ActionList is contained inside ActionMenu, we could use that to throw a warning
I love this! Thanks for the context. I made it invariant
to throw an error. Because first, it is a new component and it won't break anything. Second, when there is a heading the list will be labelled by the heading and completely disregard the button name. This could potentially be misleading.
All that said, if you think that is unnecessary and very little chance of creating a misleading experience, happy to make it warning as well 😊
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.
Overall, looks like solid work!
There are some tiny considerations here and there :)
src/ActionList/Heading.tsx
Outdated
} & SxProp | ||
|
||
export const Heading = forwardRef( | ||
({as: Component = 'h3', children, sx = defaultSxProp, visuallyHidden = false, ...props}, forwardedRef) => { |
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.
Non blocking: Should there be a default h3 or should we always ask for the heading level by making as
required without default?
Related work from eslint-plugin-primer-react:
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.
Ohh this is great! Yes I agree we should make it required!
a985caf
to
32bb440
Compare
250f91e
to
c5d2038
Compare
Integration PR is all green 🎉 https://github.com/github/github/pull/290302 merging the PR |
As a part of https://github.com/github/accessibility-audits/issues/2939, we are adding
ActionList.Heading
component that has been proposed and discussed here Most of the content below is from the API PR - Thanks to @siddharthkp 🙌🏻DESIRED SEMANTICS
CURRENT API
NEW API
Problems we are trying to solve:
Features/extensions that we are introducing to support:
Screenshots
Please provide before/after screenshots for any visual changes
Merge checklist
Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.