Skip to content

Commit 81c496c

Browse files
fix: add inline styles to sr-only spans for CSS-independent accessibility
The sr-only spans now work without requiring the datepicker stylesheet to be loaded. This fixes an issue where weekday names would show full names (e.g., "Thursday") instead of abbreviated names when CSS isn't properly applied - which can happen in certain environments like Tauri. The accessibility pattern remains the same (screen readers get the full weekday name, visual users see the abbreviation), but now it works even when CSS fails to load. Fixes #6173 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0231bbd commit 81c496c

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

src/calendar.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,19 @@ export default class Calendar extends Component<CalendarProps, CalendarState> {
509509
this.props.calendarStartDay,
510510
);
511511

512+
// Inline sr-only styles ensure weekday names work without CSS import
513+
const srOnlyStyles: React.CSSProperties = {
514+
position: "absolute",
515+
width: "1px",
516+
height: "1px",
517+
padding: 0,
518+
margin: "-1px",
519+
overflow: "hidden",
520+
clipPath: "inset(50%)",
521+
whiteSpace: "nowrap",
522+
border: 0,
523+
};
524+
512525
const dayNames: React.ReactElement[] = [];
513526
if (this.props.showWeekNumbers) {
514527
dayNames.push(
@@ -517,7 +530,9 @@ export default class Calendar extends Component<CalendarProps, CalendarState> {
517530
className={`react-datepicker__day-name ${disabled ? "react-datepicker__day-name--disabled" : ""}`}
518531
role="columnheader"
519532
>
520-
<span className="react-datepicker__sr-only">Week number</span>
533+
<span className="react-datepicker__sr-only" style={srOnlyStyles}>
534+
Week number
535+
</span>
521536
<span aria-hidden="true">{this.props.weekLabel || "#"}</span>
522537
</div>,
523538
);
@@ -568,7 +583,9 @@ export default class Calendar extends Component<CalendarProps, CalendarState> {
568583
disabled ? "react-datepicker__day-name--disabled" : "",
569584
)}
570585
>
571-
<span className="react-datepicker__sr-only">{fullDayName}</span>
586+
<span className="react-datepicker__sr-only" style={srOnlyStyles}>
587+
{fullDayName}
588+
</span>
572589
<span aria-hidden="true">{weekDayName}</span>
573590
</div>
574591
);

0 commit comments

Comments
 (0)