From 0a617f0c0979a477568147760644d8037eeb9385 Mon Sep 17 00:00:00 2001 From: Jonathan Joelson Date: Mon, 9 Oct 2023 14:20:38 -0400 Subject: [PATCH] Exclude semantics on outside days when not visible Currently, when `CalendarStyle.outsideDaysVisible` is set to false the table cells representing outside days can be focused by screen readers. Nothing is read when an outside day is focused, so screen reader users are likely to be confused and may not realize they need to skip over several empty cells. This commit excludes semantics on those empty cells when `CalendarStyle.outsideDaysVisible` is false. --- lib/src/table_calendar.dart | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/lib/src/table_calendar.dart b/lib/src/table_calendar.dart index bcd52656..969b9479 100644 --- a/lib/src/table_calendar.dart +++ b/lib/src/table_calendar.dart @@ -344,11 +344,6 @@ class _TableCalendarState extends State> { } void _onDayTapped(DateTime day) { - final isOutside = day.month != _focusedDay.value.month; - if (isOutside && _shouldBlockOutsideDays) { - return; - } - if (_isDayDisabled(day)) { return widget.onDisabledDayTapped?.call(day); } @@ -374,11 +369,6 @@ class _TableCalendarState extends State> { } void _onDayLongPressed(DateTime day) { - final isOutside = day.month != _focusedDay.value.month; - if (isOutside && _shouldBlockOutsideDays) { - return; - } - if (_isDayDisabled(day)) { return widget.onDisabledDayLongPressed?.call(day); } @@ -556,6 +546,14 @@ class _TableCalendarState extends State> { return dowCell; }, dayBuilder: (context, day, focusedMonth) { + final isOutside = day.month != focusedMonth.month; + + if (isOutside && _shouldBlockOutsideDays) { + return ExcludeSemantics( + child: Container(), + ); + } + return GestureDetector( behavior: widget.dayHitTestBehavior, onTap: () => _onDayTapped(day), @@ -570,12 +568,6 @@ class _TableCalendarState extends State> { } Widget _buildCell(DateTime day, DateTime focusedDay) { - final isOutside = day.month != focusedDay.month; - - if (isOutside && _shouldBlockOutsideDays) { - return Container(); - } - return LayoutBuilder( builder: (context, constraints) { final shorterSide = constraints.maxHeight > constraints.maxWidth @@ -618,6 +610,7 @@ class _TableCalendarState extends State> { final isToday = isSameDay(day, widget.currentDay); final isDisabled = _isDayDisabled(day); final isWeekend = _isWeekend(day, weekendDays: widget.weekendDays); + final isOutside = day.month != focusedDay.month; Widget content = CellContent( key: ValueKey('CellContent-${day.year}-${day.month}-${day.day}'),