-
Notifications
You must be signed in to change notification settings - Fork 127
Remove unnecessary aria-label defaults from Details component #3534
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
Conversation
🦋 Changeset detectedLatest commit: e0e0e33 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Co-authored-by: jonrohan <[email protected]>
@copilot address the test failures in |
Co-authored-by: jonrohan <[email protected]>
Fixed the system test failures in
The tests now correctly validate the new behavior where aria-labels are only set when explicitly provided by users. Commit: b4dc8ee |
There was a problem hiding this 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 refactors the Details component to stop injecting default aria-label
attributes unless users explicitly provide them, improving accessibility by allowing screen readers to rely on native element behavior.
- Ruby component now only adds
aria-label
anddata-aria-label-*
when explicit values are passed - TypeScript toggle logic updated to conditionally set
aria-label
based ondata-aria-label-*
presence - System and component tests updated to verify absence of default labels and correct explicit behavior
- Preview updated to demonstrate explicit aria-label usage
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
test/system/beta/details_test.rb | Updated system tests to assert no default aria-label and added checks for explicit labels |
test/components/beta/details_test.rb | Added component tests for partial, absent, and explicit aria-label scenarios |
previews/primer/beta/details_preview.rb | Introduced preview variant demonstrating explicit aria-label usage |
app/components/primer/beta/details_toggle_element.ts | Changed toggle logic to only set aria-label when data-aria-label-* attrs exist |
app/components/primer/beta/details.rb | Modified component to only include aria-label and data-aria-label-* when provided |
.changeset/popular-lizards-attack.md | Added patch summary for removing default aria-label behavior |
Comments suppressed due to low confidence (2)
app/components/primer/beta/details.rb:32
- [nitpick] Add or update doc comments for the
Details
component to explain thataria_label_closed
andaria_label_open
are now optional and only applied when explicitly provided, and that default labels are no longer set.
class Details < Primer::Component
test/system/beta/details_test.rb:28
- [nitpick] Rename this test method to mirror the click test naming (e.g.,
test_no_aria_labels_by_default_on_keyboard
) for consistency and clarity.
def test_no_aria_labels_by_default_keyboard
this.summaryTarget.setAttribute('aria-label', ariaLabelClosed) | ||
const ariaLabelClosed = this.summaryTarget.getAttribute('data-aria-label-closed') | ||
if (ariaLabelClosed) { | ||
this.summaryTarget.setAttribute('aria-label', ariaLabelClosed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that when no data-aria-label-closed
is provided, any existing aria-label
attribute is removed to avoid stale labels. For example, call this.summaryTarget.removeAttribute('aria-label')
in the branch where ariaLabelClosed
is falsy.
this.summaryTarget.setAttribute('aria-label', ariaLabelClosed) | |
this.summaryTarget.setAttribute('aria-label', ariaLabelClosed) | |
} else { | |
this.summaryTarget.removeAttribute('aria-label') |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't seem like this would hurt but not sure if it can get in this state 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for jumping on this one so quick ✨ !
I scanned through the changes and it makes sense to me, and will make it super easy to opt-out of aria-labels. Will leave a 👍 since also dropped extensive tests for the behavior but np if you want approval from other folks ✌️
# Should not have aria-label attribute | ||
refute_selector("summary[aria-label]") | ||
# Should not have data-aria-label attributes | ||
refute_selector("summary[data-aria-label-closed]") | ||
refute_selector("summary[data-aria-label-open]") | ||
# Should still have aria-expanded | ||
assert_selector("summary[aria-expanded=false]") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is pretty verbose with the comments 😅
# Only add aria-label if explicitly provided | ||
if aria_label_closed || aria_label_open | ||
current_label = open? ? (aria_label_open || ARIA_LABEL_OPEN_DEFAULT) : (aria_label_closed || ARIA_LABEL_CLOSED_DEFAULT) | ||
aria_attributes[:label] = current_label | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh ok I was little confused at first but the test clarified -- so if you provide only one label but not the other, the state without a label will use a default label 👍
this.summaryTarget.setAttribute('aria-label', ariaLabelClosed) | ||
const ariaLabelClosed = this.summaryTarget.getAttribute('data-aria-label-closed') | ||
if (ariaLabelClosed) { | ||
this.summaryTarget.setAttribute('aria-label', ariaLabelClosed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't seem like this would hurt but not sure if it can get in this state 🤔
Problem
The Details component was always setting
aria-label
attributes with default values ("Expand"/"Collapse"), even when users didn't explicitly provide them. This created accessibility issues:<details>
elementsSolution
Modified the Details component to only set
aria-label
attributes when explicitly provided by users:Ruby Component Changes
data-aria-label-*
attributes whenaria_label_open
oraria_label_closed
are providedaria-label
when explicit aria-labels are givenaria-expanded
behavior for proper state communicationTypeScript Element Changes
aria-label
during toggle whendata-aria-label-*
attributes existBefore (problematic):
After (improved):
Testing
Benefits
Fixes #3533.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
accounts.google.com
/opt/google/chrome/chrome --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --disable-dev-shm-usage --use-angle=swiftshader-webgl --mute-audio --crashpad-handler-pid=4729 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/ferrum_user_data_dir_20250611-4700-nm8t1u --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,7696498983390953603,2146872180022467109,262144 --enable-features=NetworkService,NetworkServiceInProcess --disable-features=IsolateOrigins,PaintHolding,TranslateUI,site-per-process --variations-seed-version
(dns block)/opt/google/chrome/chrome --headless --disable-gpu --hide-scrollbars --mute-audio --enable-automation --disable-web-security --disable-session-crashed-bubble --disable-breakpad --disable-sync --no-first-run --use-mock-keychain --keep-alive-for-test --disable-popup-blocking --disable-extensions --disable-component-extensions-with-REDACTED-pages --disable-hang-monitor --disable-features=site-per-process,IsolateOrigins,TranslateUI --disable-translate --disable-REDACTED-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-client-side-phishing-detection --disable-default-apps --disable-dev-shm-usage --disable-ipc-flooding-protection --disable-prompt-on-repost --disable-renderer-REDACTEDing --disable-site-isolation-trials --force-color-profile=srgb --metrics-recording-only --safebrowsing-disable-auto-update --password-store=basic --no-startup-window --remote-debugging-port=0 --remote-debugging-address=127.0.0.1 --window-size=1024,768 --user-data-dir=/tmp/ferrum_user_data_dir_20250611-4700-nm8t1u --noerrdialogs --ozone-platform=headless --ozone-override-screen-size=800,600 --use-angle=swiftshader-webgl
(dns block)/opt/google/chrome/chrome --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --disable-dev-shm-usage --use-angle=swiftshader-webgl --mute-audio --crashpad-handler-pid=4759 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/ferrum_user_data_dir_20250611-4700-57js7g --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,15882939688443903777,17075563584011957770,262144 --enable-features=NetworkService,NetworkServiceInProcess --disable-features=IsolateOrigins,PaintHolding,TranslateUI,site-per-process --variations-seed-version
(dns block)clients2.google.com
/opt/google/chrome/chrome --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --disable-dev-shm-usage --use-angle=swiftshader-webgl --mute-audio --crashpad-handler-pid=4729 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/ferrum_user_data_dir_20250611-4700-nm8t1u --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,7696498983390953603,2146872180022467109,262144 --enable-features=NetworkService,NetworkServiceInProcess --disable-features=IsolateOrigins,PaintHolding,TranslateUI,site-per-process --variations-seed-version
(dns block)/opt/google/chrome/chrome --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --disable-dev-shm-usage --use-angle=swiftshader-webgl --mute-audio --crashpad-handler-pid=4759 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/ferrum_user_data_dir_20250611-4700-57js7g --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,15882939688443903777,17075563584011957770,262144 --enable-features=NetworkService,NetworkServiceInProcess --disable-features=IsolateOrigins,PaintHolding,TranslateUI,site-per-process --variations-seed-version
(dns block)/opt/google/chrome/chrome --headless --disable-gpu --hide-scrollbars --mute-audio --enable-automation --disable-web-security --disable-session-crashed-bubble --disable-breakpad --disable-sync --no-first-run --use-mock-keychain --keep-alive-for-test --disable-popup-blocking --disable-extensions --disable-component-extensions-with-REDACTED-pages --disable-hang-monitor --disable-features=site-per-process,IsolateOrigins,TranslateUI --disable-translate --disable-REDACTED-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-client-side-phishing-detection --disable-default-apps --disable-dev-shm-usage --disable-ipc-flooding-protection --disable-prompt-on-repost --disable-renderer-REDACTEDing --disable-site-isolation-trials --force-color-profile=srgb --metrics-recording-only --safebrowsing-disable-auto-update --password-store=basic --no-startup-window --remote-debugging-port=0 --remote-debugging-address=127.0.0.1 --window-size=1024,768 --user-data-dir=/tmp/ferrum_user_data_dir_20250611-4700-57js7g --noerrdialogs --ozone-platform=headless --ozone-override-screen-size=800,600 --use-angle=swiftshader-webgl
(dns block)safebrowsingohttpgateway.googleapis.com
/opt/google/chrome/chrome --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --disable-dev-shm-usage --use-angle=swiftshader-webgl --mute-audio --crashpad-handler-pid=4729 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/ferrum_user_data_dir_20250611-4700-nm8t1u --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,7696498983390953603,2146872180022467109,262144 --enable-features=NetworkService,NetworkServiceInProcess --disable-features=IsolateOrigins,PaintHolding,TranslateUI,site-per-process --variations-seed-version
(dns block)/opt/google/chrome/chrome --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --disable-dev-shm-usage --use-angle=swiftshader-webgl --mute-audio --crashpad-handler-pid=4759 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/ferrum_user_data_dir_20250611-4700-57js7g --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,15882939688443903777,17075563584011957770,262144 --enable-features=NetworkService,NetworkServiceInProcess --disable-features=IsolateOrigins,PaintHolding,TranslateUI,site-per-process --variations-seed-version
(dns block)/opt/google/chrome/chrome --headless --disable-gpu --hide-scrollbars --mute-audio --enable-automation --disable-web-security --disable-session-crashed-bubble --disable-breakpad --disable-sync --no-first-run --use-mock-keychain --keep-alive-for-test --disable-popup-blocking --disable-extensions --disable-component-extensions-with-REDACTED-pages --disable-hang-monitor --disable-features=site-per-process,IsolateOrigins,TranslateUI --disable-translate --disable-REDACTED-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-client-side-phishing-detection --disable-default-apps --disable-dev-shm-usage --disable-ipc-flooding-protection --disable-prompt-on-repost --disable-renderer-REDACTEDing --disable-site-isolation-trials --force-color-profile=srgb --metrics-recording-only --safebrowsing-disable-auto-update --password-store=basic --no-startup-window --remote-debugging-port=0 --remote-debugging-address=127.0.0.1 --window-size=1024,768 --user-data-dir=/tmp/ferrum_user_data_dir_20250611-4700-57js7g --noerrdialogs --ozone-platform=headless --ozone-override-screen-size=800,600 --use-angle=swiftshader-webgl
(dns block)If you need me to access, download, or install something from one of these locations, you can either: