Skip to content

Support dynamic labels for multiple variant SelectPanel#3825

Open
myabc wants to merge 2 commits intoprimer:mainfrom
opf:feature/select-panel-dynamic-label-multiple
Open

Support dynamic labels for multiple variant SelectPanel#3825
myabc wants to merge 2 commits intoprimer:mainfrom
opf:feature/select-panel-dynamic-label-multiple

Conversation

@myabc
Copy link
Contributor

@myabc myabc commented Dec 26, 2025

What are you trying to accomplish?

Screenshots

image

Integration

List the issues that this change affects.

Closes #3824

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.

What approach did you choose and why?

Anything you want to highlight for special attention from reviewers?

Accessibility

  • Fixes axe scan violation - This change fixes an existing axe scan violation.
  • No new axe scan violation - This change does not introduce any new axe scan violations.
  • New axe violation - This change introduces a new axe scan violation. Please describe why the violation cannot be resolved below.

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.

@changeset-bot
Copy link

changeset-bot bot commented Dec 26, 2025

🦋 Changeset detected

Latest commit: b084a5a

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

This PR includes changesets to release 1 package
Name Type
@primer/view-components 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

@myabc myabc force-pushed the feature/select-panel-dynamic-label-multiple branch 2 times, most recently from 35d5564 to ef8163d Compare December 26, 2025 01:54
@myabc myabc changed the title Support dynamic labels for multiple SelectPanel Support dynamic labels for multiple variant SelectPanel Dec 26, 2025
@myabc myabc marked this pull request as ready for review December 26, 2025 02:11
@myabc myabc requested a review from a team as a code owner December 26, 2025 02:11
@myabc myabc requested review from Copilot and siddharthkp December 26, 2025 02:11
Copy link
Contributor

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 adds support for dynamic labels in SelectPanel's multiple select variant. Previously, dynamic labels only worked with the single select variant. Now both single and multiple variants can display selected item labels dynamically in the panel invoker button.

Key Changes:

  • Extended dynamic label functionality to support multiple select variant, displaying selected items as comma-separated values
  • Updated preview components to accept a select_variant parameter for testing both single and multiple variants
  • Added comprehensive test coverage for both single and multiple select variants with dynamic labels

Reviewed changes

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

Show a summary per file
File Description
app/components/primer/alpha/select_panel_element.ts Added logic to handle dynamic labels for multiple select variant by collecting and joining labels from all selected items
previews/primer/alpha/select_panel_preview.rb Added select_variant parameter to dynamic label preview methods to support testing both variants
previews/primer/alpha/select_panel_preview/with_dynamic_label.html.erb Changed hardcoded :single to parameterized select_variant
previews/primer/alpha/select_panel_preview/with_dynamic_label_and_aria_prefix.html.erb Changed hardcoded :single to parameterized select_variant
test/system/alpha/select_panel_test.rb Added four new test cases covering dynamic labels for both single and multiple variants, with and without aria prefix; cleaned up trailing whitespace
.changeset/afraid-monkeys-unite.md Added changeset documenting this minor feature addition

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

itemLabel = this.querySelector(`[${this.ariaSelectionType}=true] .ActionListItem-label`)?.textContent
} else if (this.selectVariant === 'multiple') {
itemLabel = Array.from(this.querySelectorAll(`[${this.ariaSelectionType}=true] .ActionListItem-label`))
.map(label => label.textContent.trim())
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

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

The code assumes label.textContent is not null when calling .trim(). Although textContent typically returns an empty string rather than null, it would be safer to add null checking (e.g., label.textContent?.trim()) to handle edge cases consistently with line 956.

Suggested change
.map(label => label.textContent.trim())
.map(label => label.textContent?.trim() ?? '')

Copilot uses AI. Check for mistakes.
itemLabel = this.querySelector(`[${this.ariaSelectionType}=true] .ActionListItem-label`)?.textContent
} else if (this.selectVariant === 'multiple') {
itemLabel = Array.from(this.querySelectorAll(`[${this.ariaSelectionType}=true] .ActionListItem-label`))
.map(label => label.textContent.trim())
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

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

If any label has null or empty textContent, the resulting string could include empty entries separated by commas (e.g., "Item 1, , Item 3"). Consider filtering out null or empty values before joining to avoid displaying empty entries in the label.

Suggested change
.map(label => label.textContent.trim())
.map(label => label.textContent?.trim() || '')
.filter(labelText => labelText.length > 0)

Copilot uses AI. Check for mistakes.
Comment on lines +956 to +960
itemLabel = this.querySelector(`[${this.ariaSelectionType}=true] .ActionListItem-label`)?.textContent
} else if (this.selectVariant === 'multiple') {
itemLabel = Array.from(this.querySelectorAll(`[${this.ariaSelectionType}=true] .ActionListItem-label`))
.map(label => label.textContent.trim())
.join(', ')
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

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

The code doesn't call .trim() on the textContent for single select variant (line 956), but does call it for the multiple select variant (line 959). This inconsistency could lead to differences in whitespace handling between the two variants. Consider applying .trim() consistently in both cases.

Copilot uses AI. Check for mistakes.
@myabc myabc force-pushed the feature/select-panel-dynamic-label-multiple branch from 54dcba6 to df138f2 Compare December 26, 2025 02:22
@siddharthkp siddharthkp requested a review from jonrohan December 29, 2025 09:54
@siddharthkp
Copy link
Member

Hi! Happy holidays!

I'm not the right person to review this, so I'm going to assign it to @jonrohan to have a look when he's back from the holidays.

@siddharthkp siddharthkp removed their request for review January 5, 2026 09:20
@myabc myabc force-pushed the feature/select-panel-dynamic-label-multiple branch from df138f2 to b084a5a Compare January 6, 2026 20:07
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.

SelectPanel multiple variant does not support dynamic labels

2 participants

Comments