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 footnotes component #707

Merged
merged 7 commits into from
Aug 29, 2024
Merged

Add footnotes component #707

merged 7 commits into from
Aug 29, 2024

Conversation

rezrah
Copy link
Collaborator

@rezrah rezrah commented Aug 21, 2024

Summary

Part of https://github.com/github/primer/issues/3673

Adds a new Footnotes component to the library.

Displays two types of footnotes content: citation and disclaimer.

🔗 Documentation preview
🔗 Real-world example
🔗 Citation examples in Storybook
🔗 Paragraph (disclaimer) examples in Storybook

List of notable changes:

  • added component
  • added documentation
  • added storybook stories
  • added unit tests
  • added changeset
  • added VRT

What should reviewers focus on?

Steps to test:

Use the following links:

Supporting resources (related issues, external links, etc):

Contributor checklist:

  • All new and existing CI checks pass
  • Tests prove that the feature works and covers both happy and unhappy paths
  • Any drop in coverage, breaking changes or regressions have been documented above
  • New visual snapshots have been generated / updated for any UI changes
  • All developer debugging and non-functional logging has been removed
  • Related issues have been referenced in the PR description

Reviewer checklist:

  • Check that pull request and proposed changes adhere to our contribution guidelines and code of conduct
  • Check that tests prove the feature works and covers both happy and unhappy paths
  • Check that there aren't other open Pull Requests for the same update/change

Screenshots:

Screenshot 2024-08-21 at 17 28 22

Screenshot 2024-08-21 at 17 28 48

Copy link

changeset-bot bot commented Aug 21, 2024

🦋 Changeset detected

Latest commit: fe9283d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@primer/react-brand Minor
@primer/brand-primitives Minor
@primer/brand-e2e Minor
@primer/brand-fonts Minor
@primer/brand-config Minor
@primer/brand-storybook 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 Aug 21, 2024

🟢 No design token changes found

Copy link
Contributor

github-actions bot commented Aug 21, 2024

🟢 No visual differences found

Our visual comparison tests did not find any differences in the UI.

@rezrah rezrah marked this pull request as ready for review August 21, 2024 17:19
Copy link

@simmonsjenna simmonsjenna left a comment

Choose a reason for hiding this comment

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

LGTM — thank you! 🙌

Copy link
Contributor

@joshfarrant joshfarrant 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!

packages/react/src/Footnotes/Footnotes.tsx Show resolved Hide resolved
packages/react/src/Footnotes/Footnotes.tsx Show resolved Hide resolved
className={clsx(styles.Footnotes, styles['Footnotes--variant-citations'], className)}
{...(rest as BaseProps<HTMLOListElement>)}
>
{children}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think we need to guard against someone passing as="ol" with variant="disclaimer"? That would render an <ol> with <Text> children.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good question. variant isn't documented anywhere outside of source code, and I'm using it as an internal-only prop. Bit of a trade-off between adding more code to guard it vs the managing the complexity of adding them.

In this case, because its undocumented I think i prefer to not add the code, though I have now prepended _ to the start to make it clearer for TS users. Maybe this is enough of a guard? Could also go more heavy handed, add warnings, pass the as prop down and add conditional logic to prevent this configuration from being possible but we could always add that down the line too if we're seeing a lot of misuse.

packages/react/src/Footnotes/Footnotes.test.tsx Outdated Show resolved Hide resolved
packages/react/src/Footnotes/Footnotes.test.tsx Outdated Show resolved Hide resolved
packages/react/src/Footnotes/Footnotes.tsx Show resolved Hide resolved
Comment on lines 19 to 48
it('renders the default footnotes correctly', async () => {
const items = ['Citation 1', 'Citation 2', 'Citation 3']

const {getByTestId, container} = render(
<Footnotes data-testid="footnotes">
{items.map((citation, index) => (
<Footnotes.Item data-testid={`item-${index}`} key={citation}>
{citation}
</Footnotes.Item>
))}
</Footnotes>,
)

const results = await axe(container)
expect(results).toHaveNoViolations()

const rootEl = getByTestId('footnotes')

expect(rootEl).toBeInTheDocument()
expect(rootEl.tagName).toEqual('OL')

let index = 0
for (const item of items) {
const itemEl = getByTestId(`item-${index}`)
expect(itemEl).toHaveTextContent(item)
expect(itemEl).toBeInTheDocument()
expect(itemEl.tagName).toEqual('LI')
index++
}
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a suggestion, but you could get rid of test-ids completely here. Testing Library lists them as their lowest-priority queries and as such they recommend avoiding them unless absolutely necessary

  it('renders the default footnotes correctly', async () => {
    const items = ['Citation 1', 'Citation 2', 'Citation 3']

    const {getByRole, container} = render(
      <Footnotes>
        {items.map((citation, index) => (
          <Footnotes.Item data-testid={`item-${index}`} key={citation}>
            {citation}
          </Footnotes.Item>
        ))}
      </Footnotes>,
    )

    const results = await axe(container)
    expect(results).toHaveNoViolations()

    const listEl = getByRole('list')

    expect(listEl).toBeInTheDocument()
    expect(listEl.tagName).toEqual('OL')

    for (const item of items) {
      expect(getByRole('listitem', {name: item})).toBeInTheDocument()
    }
  })

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks.

expect(getByRole('listitem', {name: item})).toBeInTheDocument()

☝️ doesn't work because of the way the content is nested inside another tag of the listitem. Relevant WCAG guidelines here. I've instead used the textContent property on the listitem to infer the correct value. IMO it's a bit more convoluted now, but happy to keep it like this.

If you're wondering why the assertion against tagName is still there, it's because the listitem role can be manually assigned to a different tag, so this makes sure that doesn't happen/

Copy link
Contributor

@joshfarrant joshfarrant 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!

@danielguillan
Copy link
Contributor

Footnotes highlight

From a design perspective, the footnotes highlight doesn't really work. In dark mode, the contrast between the text and background is insufficient (4.22). Additionally, the yellow in dark mode clashes with the rest of the page. Finally, the highlight should only wrap the text, including the counter, instead of going full-width.

To unblock this PR. I suggest we remove the highlight from this initial version of the component while we figure out a better visual treatment.

@rezrah
Copy link
Collaborator Author

rezrah commented Aug 28, 2024

To unblock this PR. I suggest we remove the highlight from this initial version of the component while we figure out a better visual treatment.

@danielguillan the target highlight has been removed

@rezrah rezrah merged commit 715dfbb into main Aug 29, 2024
17 of 18 checks passed
@rezrah rezrah deleted the rezrah/add-footnotes-component branch August 29, 2024 09:48
@primer-css primer-css mentioned this pull request Aug 28, 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.

4 participants