Skip to content

SelectPanel: Add default empty message to announcement #6346

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

TylerJDev
Copy link
Member

@TylerJDev TylerJDev commented Jul 21, 2025

Addresses multiple audit issues: https://github.com/github/accessibility-audits/issues/12437, https://github.com/github/accessibility-audits/issues/11114

Ensures that the announcement for no items takes from DefaultEmptyMessage instead

Changelog

Changed

  • Adds default message for empty announcements in FilteredActionList and SelectPanel

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

Merge checklist

@TylerJDev TylerJDev requested a review from francinelucca July 21, 2025 16:14
Copy link

changeset-bot bot commented Jul 21, 2025

🦋 Changeset detected

Latest commit: 8f3edce

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 Patch

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 github-actions bot added staff Author is a staff member integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm labels Jul 21, 2025
Copy link
Contributor

👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks!

Copy link
Member

@francinelucca francinelucca left a comment

Choose a reason for hiding this comment

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

Tagged @llastflowers for review since this might intersect with the work she's doing as part of https://github.com/github/primer/issues/5377

Copy link
Contributor

@llastflowers llastflowers left a comment

Choose a reason for hiding this comment

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

I left one comment, and the rest of the changes look fine to me! I'm wondering if the original message mismatch with the announcement had to do with the two different types of 'empty' messages being conflated? 🤔

Regarding my work on https://github.com/github/primer/issues/5377, I think I can build those changes on top of this without any issues!

Copy link
Contributor

github-actions bot commented Jul 22, 2025

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 92.24 KB (-0.03% 🔽)
packages/react/dist/browser.umd.js 92.36 KB (+0.01% 🔺)

@github-actions github-actions bot requested a deployment to storybook-preview-6346 July 22, 2025 19:28 Abandoned
Comment on lines 33 to 36
const EMPTY_MESSAGE = {
title: 'You haven’t created any items yet',
description: 'Please add or create new items to populate the list.',
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Added a const to hold our default messages. If we ever decide not to provide a default, we'll need to remove this.

@@ -228,12 +232,12 @@ function Panel({
const onListContainerRefChanged: FilteredActionListProps['onListContainerRefChanged'] = useCallback(
(node: HTMLElement | null) => {
setListContainerElement(node)
if (!node && needsNoItemsAnnouncement) {
if (!node && needsNoItemsAnnouncement && !usingModernActionList) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think we need to announce through SelectPanel if it's not using the modern action list. I was getting multiple of the same announcements, some through useAnnouncements and others through this file.

Comment on lines +45 to +48
messageText?: {
title: string
description: string
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This is just so TypeScript doesn't yell. Won't be needed once we remove the FF.

@TylerJDev TylerJDev marked this pull request as ready for review July 22, 2025 19:51
@Copilot Copilot AI review requested due to automatic review settings July 22, 2025 19:51
@TylerJDev TylerJDev requested a review from a team as a code owner July 22, 2025 19:51
@TylerJDev TylerJDev requested a review from joshblack July 22, 2025 19:51
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ensures that SelectPanel components provide proper accessibility announcements for empty states by using default or provided empty messages instead of generic fallback text. The changes address accessibility audit issues by making screen reader announcements more informative.

Key changes:

  • Extracts default empty message into a reusable constant object
  • Updates announcement functions to use structured message content instead of hardcoded strings
  • Adds messageText prop to FilteredActionList components for configurable empty state announcements

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
SelectPanel.tsx Refactors empty message handling and updates announcement logic to use structured message content
SelectPanel.examples.stories.tsx Adds story demonstrating default message functionality
useAnnouncements.tsx Updates hook to accept and use structured message parameter for empty state announcements
FilteredActionListWithModernActionList.tsx Adds messageText prop and passes it to useAnnouncements hook
FilteredActionListWithDeprecatedActionList.tsx Adds messageText prop interface (unused in deprecated implementation)
fresh-lines-guess.md Documents the patch-level change in changelog

description:
typeof message?.body === 'string'
? message.body
: EMPTY_MESSAGE.description || EMPTY_MESSAGE.description,
Copy link
Preview

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

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

The fallback logic EMPTY_MESSAGE.description || EMPTY_MESSAGE.description is redundant. This should likely be message.body || EMPTY_MESSAGE.description to properly fallback to the default when message.body is falsy.

Suggested change
: EMPTY_MESSAGE.description || EMPTY_MESSAGE.description,
: message.body || EMPTY_MESSAGE.description,

Copilot uses AI. Check for mistakes.

@@ -92,7 +93,7 @@ export const useAnnouncements = (
liveRegion?.clear() // clear previous announcements

if (items.length === 0 && !loading) {
announce('No matching items.', {delayMs})
announce(`${message?.title}. ${message?.description}`, {delayMs})
Copy link
Preview

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

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

When message is undefined, this will announce 'undefined. undefined' to screen readers. Add a fallback: announce(message ? ${message.title}. ${message.description} : 'No matching items.', {delayMs})

Suggested change
announce(`${message?.title}. ${message?.description}`, {delayMs})
announce(message ? `${message.title}. ${message.description}` : 'No matching items.', {delayMs})

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm staff Author is a staff member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants