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

Add ActionList.Heading component #3581

Merged
merged 14 commits into from
Sep 27, 2023
Merged

Add ActionList.Heading component #3581

merged 14 commits into from
Sep 27, 2023

Conversation

broccolinisoup
Copy link
Member

@broccolinisoup broccolinisoup commented Aug 1, 2023

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

<h3 id="heading-id" className="sx-generated">Issue actions</h2>
<ul role="list" aria-labelledby="heading-id">
  <li>
    <span><!-- leading visual --></span>
    <span>Lock conversation</span>
  </li>
  <li>
    <span><!-- leading visual --></span>
    <span>Unpin issue</span>
    <span><!-- description --></span>
  </li>
</ul> 

CURRENT API

<Heading 
  as="h3"
  id="heading-id" 
  sx={{fontSize: 0, color:'fg.muted', paddingX: 3}}
>
  Issue actions
</Heading>

<ActionList role="list" aria-labelledby="heading-id">
  <ActionList.Item>
    {/* leading visual */}
    Lock conversation
  </ActionList.Item>
  <ActionList.Item>
    {/* leading visual */}
    Unpin issue
    {/* description */}
   </ActionList.Item>
</ActionList>

NEW API

<ActionList role="list">
 <ActionList.Heading as="h3">Issue actions</ActionList.Heading>
 <ActionList.Item>
    {/* leading visual */}
    Lock conversation
 </ActionList.Item>
 <ActionList.Item>
    {/* leading visual */}
    Unpin issue
    {/* description */}
 </ActionList.Item>
</ActionList>

Problems we are trying to solve:

  • ✅ Easy to miss, to not add heading at all (Missing heading)
  • ✅ Need to bring your own id + aria-labelledby (Heading but not connected)
  • ✅ Need to bring your own heading styles (Inconistent heading styles)
  • ✅ Need to bring your own padding to align with ActionList's default padding which depends on variant prop on ActionList (Inconsistent space between heading and list)

Features/extensions that we are introducing to support:

  • ✅ Add arbitrary attributes to underlying element like id or data-test-id
  • ✅ Make the heading visually hidden but readable by screen readers (see [Primer][React] ActionList semantics accessibility-audits#2939 (comment) thread for context)
  • ✅ Customize heading styles (not recommended, but for exceptions)

Screenshots

Please provide before/after screenshots for any visual changes

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.

@changeset-bot
Copy link

changeset-bot bot commented Aug 1, 2023

🦋 Changeset detected

Latest commit: c68c0cc

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

@github-actions
Copy link
Contributor

github-actions bot commented Aug 1, 2023

size-limit report 📦

Path Size
dist/browser.esm.js 104.52 KB (+0.16% 🔺)
dist/browser.umd.js 105.1 KB (+0.15% 🔺)

@broccolinisoup broccolinisoup temporarily deployed to github-pages August 1, 2023 02:53 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3581 August 1, 2023 02:54 Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3581 August 1, 2023 03:14 Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3581 August 1, 2023 03:15 Inactive
@broccolinisoup broccolinisoup temporarily deployed to github-pages August 1, 2023 03:18 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3581 August 1, 2023 03:19 Inactive
@broccolinisoup broccolinisoup marked this pull request as ready for review August 1, 2023 04:16
@@ -41,6 +42,109 @@ export const SimpleList = () => (
</ActionList>
)

export const WithHeading = () => (
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 we should add this heading to docs and all stories in another PR after this, to show that this is the recommended usage.

Copy link
Member Author

@broccolinisoup broccolinisoup Aug 9, 2023

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,
})
Copy link
Member

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?

Copy link
Member Author

@broccolinisoup broccolinisoup Aug 9, 2023

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

Copy link
Member Author

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?

Copy link
Member

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 :)

Copy link
Member

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

Copy link
Member Author

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 😊

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.

Overall, looks like solid work!

There are some tiny considerations here and there :)

@broccolinisoup broccolinisoup temporarily deployed to github-pages August 9, 2023 01:43 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3581 August 9, 2023 01:44 Inactive
@broccolinisoup broccolinisoup temporarily deployed to github-pages September 1, 2023 02:25 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3581 September 1, 2023 02:25 Inactive
} & SxProp

export const Heading = forwardRef(
({as: Component = 'h3', children, sx = defaultSxProp, visuallyHidden = false, ...props}, forwardedRef) => {
Copy link
Member

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:

Copy link
Member Author

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!

@github-actions github-actions bot temporarily deployed to storybook-preview-3581 September 10, 2023 22:10 Inactive
@broccolinisoup broccolinisoup temporarily deployed to github-pages September 12, 2023 01:27 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3581 September 12, 2023 01:27 Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3581 September 12, 2023 01:40 Inactive
@broccolinisoup broccolinisoup temporarily deployed to github-pages September 12, 2023 01:44 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3581 September 12, 2023 01:45 Inactive
@broccolinisoup broccolinisoup temporarily deployed to github-pages September 12, 2023 02:41 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3581 September 12, 2023 02:42 Inactive
@broccolinisoup broccolinisoup temporarily deployed to github-pages September 20, 2023 02:38 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3581 September 20, 2023 02:39 Inactive
@broccolinisoup broccolinisoup temporarily deployed to github-pages September 27, 2023 01:08 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3581 September 27, 2023 01:09 Inactive
@broccolinisoup
Copy link
Member Author

Integration PR is all green 🎉 https://github.com/github/github/pull/290302 merging the PR

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