Skip to content

feat(Utility): add all parameter on getDescribedElement method#7778

Merged
ArgoZhang merged 2 commits intomainfrom
fix-arch
Mar 20, 2026
Merged

feat(Utility): add all parameter on getDescribedElement method#7778
ArgoZhang merged 2 commits intomainfrom
fix-arch

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Mar 20, 2026

Link issues

fixes #7777

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

New Features:

  • Add an optional parameter to getDescribedElement to return all matching elements via querySelectorAll when requested.

Copilot AI review requested due to automatic review settings March 20, 2026 07:03
@bb-auto bb-auto bot added the enhancement New feature or request label Mar 20, 2026
@bb-auto bb-auto bot added this to the v10.4.0 milestone Mar 20, 2026
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Mar 20, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds an optional all parameter to the getDescribedElement utility to allow returning either a single matching element or all matching elements for an ARIA description selector.

File-Level Changes

Change Details Files
Extend getDescribedElement utility to optionally return all matching described elements instead of only the first.
  • Add an all boolean parameter to the getDescribedElement function signature with a default of false to preserve existing behavior.
  • Update the function to use document.querySelectorAll when all is true and document.querySelector when all is false, keeping the existing ID normalization logic intact.
  • Ensure the function still returns null when the provided element is invalid or lacks the target attribute.
src/BootstrapBlazor/wwwroot/modules/utility.js

Assessment against linked issues

Issue Objective Addressed Explanation
#7777 Add an all parameter to the getDescribedElement utility method to optionally return all matching elements instead of only the first match, while preserving existing default behavior.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@ArgoZhang ArgoZhang merged commit 67410a8 into main Mar 20, 2026
5 checks passed
@ArgoZhang ArgoZhang deleted the fix-arch branch March 20, 2026 07:03
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • With the new all flag, getDescribedElement now sometimes returns a NodeList instead of a single element; consider either keeping the return type consistent (e.g., always returning an array) or auditing and updating all call sites to handle both cases explicitly.
  • The all parameter name is a bit unclear at the call site; consider renaming it to something more explicit like returnAll or multiple to better convey that it switches between a single element and a NodeList.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- With the new `all` flag, `getDescribedElement` now sometimes returns a `NodeList` instead of a single element; consider either keeping the return type consistent (e.g., always returning an array) or auditing and updating all call sites to handle both cases explicitly.
- The `all` parameter name is a bit unclear at the call site; consider renaming it to something more explicit like `returnAll` or `multiple` to better convey that it switches between a single element and a `NodeList`.

## Individual Comments

### Comment 1
<location path="src/BootstrapBlazor/wwwroot/modules/utility.js" line_range="423-430" />
<code_context>
 }

-const getDescribedElement = (element, selector = 'aria-describedby') => {
+const getDescribedElement = (element, selector = 'aria-describedby', all = false) => {
     if (isElement(element)) {
         let id = element.getAttribute(selector)
         if (id) {
             if (id.indexOf('.') === -1) {
                 id = `#${id}`
             }
-            return document.querySelector(id)
+            return all ? document.querySelectorAll(id) : document.querySelector(id)
         }
     }
</code_context>
<issue_to_address>
**issue:** Handling multiple aria-describedby IDs with `all` is likely incorrect with the current selector construction.

With `all = true`, this now does `querySelectorAll(id)`, but `aria-describedby` often holds a space-separated list of IDs (e.g. `"id1 id2"`). That makes `id` become `"#id1 id2"`, which is parsed as a descendant selector, not multiple IDs, so it won’t reliably return all referenced elements. If `all` is meant to return all described elements, you likely need to split on whitespace, prefix each with `#`, and either build a comma-separated selector for `querySelectorAll` or use `getElementById` per ID and aggregate the results.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +423 to +430
const getDescribedElement = (element, selector = 'aria-describedby', all = false) => {
if (isElement(element)) {
let id = element.getAttribute(selector)
if (id) {
if (id.indexOf('.') === -1) {
id = `#${id}`
}
return document.querySelector(id)
return all ? document.querySelectorAll(id) : document.querySelector(id)
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: Handling multiple aria-describedby IDs with all is likely incorrect with the current selector construction.

With all = true, this now does querySelectorAll(id), but aria-describedby often holds a space-separated list of IDs (e.g. "id1 id2"). That makes id become "#id1 id2", which is parsed as a descendant selector, not multiple IDs, so it won’t reliably return all referenced elements. If all is meant to return all described elements, you likely need to split on whitespace, prefix each with #, and either build a comma-separated selector for querySelectorAll or use getElementById per ID and aggregate the results.

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

Adds an opt-in capability for getDescribedElement (utility JS helper) to return multiple matched elements, and bumps the package version for the next beta release.

Changes:

  • Extend getDescribedElement with an all parameter that switches between querySelector and querySelectorAll.
  • Bump BootstrapBlazor package version from 10.4.2-beta01 to 10.4.2-beta02.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/BootstrapBlazor/wwwroot/modules/utility.js Adds all parameter to getDescribedElement to optionally return multiple matches.
src/BootstrapBlazor/BootstrapBlazor.csproj Updates package version to 10.4.2-beta02.

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

return document.querySelector(id)
return all ? document.querySelectorAll(id) : document.querySelector(id)
}
}
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

getDescribedElement now returns different types depending on all (Element vs NodeList vs null). This makes the API easy to misuse (e.g., if (ret) ret.querySelector(...) works for Element but breaks for NodeList; also querySelectorAll returns an empty NodeList which is truthy, while the function otherwise returns null). Consider keeping the return type consistent: either split into getDescribedElement (single) + getDescribedElements (all), or when all=true always return a (possibly empty) array/NodeList and never null, and document the contract clearly for callers.

Suggested change
}
}
if (all) {
// Always return a NodeList for the "all" mode, even when there is no match,
// to mirror querySelectorAll semantics and keep the return type consistent.
return document.querySelectorAll('[data-utility-empty-aria-describedby=""]')
}

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Mar 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (6847ec2) to head (5e5947d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #7778   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          764       764           
  Lines        33960     33960           
  Branches      4675      4675           
=========================================
  Hits         33960     33960           
Flag Coverage Δ
BB 100.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(Utility): add all parameter on getDescribedElement method

2 participants