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

[WIP] Support prop to announce banner when it is shown #2583

Closed
wants to merge 13 commits into from

Conversation

khiga8
Copy link
Contributor

@khiga8 khiga8 commented Feb 9, 2024

This is a proof of concept, and has a pre-req to ship:

What are you trying to accomplish?

When banners are shown async to communicate feedback, we should either be focusing or announcing the banner content to draw attention to it. Read more at Banner docs.

This is a proof of concept to support a announce_on_show prop that, when set, announces the banner content upon it's visibility being updated by the consumer.

This should support a live region announcement being made across the following scenarios:

  • The banner is rendered as hidden. Then the consumer uses JS to unhide the banner. At this point, we want the banner to be announced when announce_on_show: true. (Test written ✅ )
  • A parent of the banner is set to hidden (e.g. an entire container). Then the consumer uses JS to unhide the container. At this point, we want the banner to be announced when announce_on_show: true is set. (Test written ✅ )
  • The banner gets dynamically injected into the DOM via JS. At this point, we want the banner to be announced when announce_on_show: true. (Needs test ❌ Any tips for how to go about dynamically injecting a view component in our system tests? )

IMPORTANT 🔈

Dynamically injected live region attributes don't work reliably so we cannot just set aria-live on the Banner and expect it to announce when the Banner appears. See Staff only: Challenges with dynamically injected live region.

This approach depends on hooking into live-region-element which is ideally already part of the page layout. As called out in the beginning, there is pre-req work necessary to support live-region. Consumer needs to add this to their page layout.

Integration

This depends on <live-region> to be part of the page layout of the repos it is called in.

List the issues that this change affects.

Relates to: https://github.com/github/accessibility/issues/5649

Risk Assessment

  • Low risk the change is small, highly observable, and easily rolled back.
  • Medium risk changes that are isolated, reduced in scope or could impact few users. The change will not impact library availability.
  • High risk changes are those that could impact customers and SLOs, low or no test coverage, low observability, or slow to rollback.

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Added/updated previews (Lookbook)
  • 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.

Copy link

changeset-bot bot commented Feb 9, 2024

⚠️ No Changeset found

Latest commit: 0d4d517

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@khiga8 khiga8 changed the title [WIP] Proof of concept to announce banner once upon showing [WIP] Support prop to announce banner when it is shown Feb 9, 2024
}
}
}
this.observer = new IntersectionObserver(callback, options)
Copy link
Contributor Author

@khiga8 khiga8 Feb 9, 2024

Choose a reason for hiding this comment

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

Looked into IntersectionObserver because it was mentioned in #2576 (comment).

I am expecting this to detect when the Banner's visibility changes from hidden to being visible.

Close review would be appreciated.

Copy link
Contributor

github-actions bot commented Feb 20, 2024

⚠️ Visual differences found

Our visual comparison tests found UI differences. Please review the differences by viewing the files changed tab to ensure that the changes were intentional.

Review visual differences

<p class="Banner-title" data-target="<%= catalyst_target(field: "titleText") %>"><%= content %></p>
<% if @description %>
<p><%= @description %></p>
<span data-target="<%= catalyst_target(field: "contentToAnnounce") %>">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The dismiss button should not be announced.

Comment on lines +2 to +3
// eslint-disable-next-line import/no-unresolved
import '@primer/live-region-element/define'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

How to fix this? Also, I noticed we don't need to make this call in other custom elements since it's exported as part of the index. Wonder if we should do the same for live-region?


assert_selector("#wrapper", visible: :visible)
assert_equal page.evaluate_script("document.querySelector('live-region').shadowRoot.querySelector('[aria-live=\"polite\"]').innerText.trim()"), "Hello."
end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want to add a test for when Primer::Alpha::Banner is dynamically injected. How should I set this up?

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.

1 participant