fix: keep sr-only weekday header text visually hidden with inline styles#6305
Open
franmc01 wants to merge 1 commit into
Open
fix: keep sr-only weekday header text visually hidden with inline styles#6305franmc01 wants to merge 1 commit into
franmc01 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens the calendar weekday header’s accessibility markup so the full weekday names and week-number label remain visually hidden even if a consumer loads an out-of-sync (older) stylesheet that lacks the .react-datepicker__sr-only rule.
Changes:
- Added a
visuallyHiddenStyleinline style object inCalendarthat mirrors the.react-datepicker__sr-onlySCSS rules. - Applied that inline style to the weekday full-name sr-only span and the week-number label sr-only span.
- Added a regression test asserting the sr-only spans include the visually-hidden inline styles.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/calendar.tsx |
Adds and applies visuallyHiddenStyle inline to the sr-only spans in the weekday header/week-number header to prevent visible overlap when CSS is missing/outdated. |
src/test/calendar_test.test.tsx |
Adds a regression test verifying the sr-only spans remain visually hidden via inline styles (independent of stylesheet presence). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6305 +/- ##
==========================================
+ Coverage 99.29% 99.31% +0.02%
==========================================
Files 30 30
Lines 3822 3823 +1
Branches 1648 1665 +17
==========================================
+ Hits 3795 3797 +2
+ Misses 26 25 -1
Partials 1 1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Linked issue: #6302
Problem
Since v8.5.0 the calendar weekday header renders a screen-reader-only span with the full day name (
Sunday,Monday, ...) next to the visible short name. The span is hidden by the.react-datepicker__sr-onlyrule (named.sr-onlyin v8.5.0–v8.6.0) shipped in the package stylesheet.When the stylesheet loaded by the consumer app does not match the installed JS version — a vendored copy of the v7 CSS, a CDN link pinned to an older version, or a stale build cache — that rule is missing, and the full day names render visibly, overlapping the short names exactly as shown in the issue screenshots. Every published version of the package ships matching JS + CSS (verified 7.7.0 through 9.1.0 across
react-datepicker.css,react-datepicker.min.css, and the CSS-modules variants), which is why the issue is not reproducible with a correct setup.Changes
This makes the component degrade gracefully instead of producing a broken header when the loaded stylesheet is out of sync: the visually-hidden styles are now also applied inline on the two sr-only spans, mirroring the
.react-datepicker__sr-onlyrule. The class name and the SCSS rule are unchanged.src/calendar.tsxvisuallyHiddenStyleconstant (mirror of the.react-datepicker__sr-onlyruleset) and applied it inline to the week-number and day-name sr-only spanssrc/test/calendar_test.test.tsxScreenshots
See the issue for before/after screenshots of the broken header (v7 stylesheet + v8/v9 JS).
To reviewers
Two intentional tradeoffs worth a conscious decision:
datepicker.scssandcalendar.tsx); they must be kept in sync if the clipping technique ever changes..react-datepicker__sr-onlywould now need!important. Given the class exists purely to hide accessible text, this seems like the right default.The added test pins that the inline styles stay applied at the JSX level; jsdom cannot reproduce the visual overlap itself.
Contribution checklist