Skip to content

Commit f51341e

Browse files
author
dandmechenko
committed
feat(CalendarView): cellFocusable prop
1 parent 652474f commit f51341e

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/components/Calendar/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ LANDING_BLOCK-->
183183
| aria-label | The control's `aria-label` attribute | `string` | |
184184
| aria-labelledby | The control's `aria-labelledby` attribute | `string` | |
185185
| autoFocus | The control's `autofocus` attribute | `boolean` | |
186+
| cellFocusable | The control's `cellFocusable` attribute | `boolean` | |
186187
| className | The control's wrapper class name | `string` | |
187188
| [defaultFocusedValue](#focused-value) | The date that is focused when the calendar first mounts (uncontrolled) | `DateTime` | |
188189
| [defaultMode](#mode) | Initial mode to show in calendar | `days` `months` `quarters` `years` | |

src/components/CalendarView/hooks/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export interface CalendarStateOptionsBase extends InputBase {
2525
autoFocus?: boolean;
2626
/** Controls the currently focused date within the calendar. */
2727
focusedValue?: DateTime | null;
28+
/** Whether to automatically focus the cell
29+
* * @default true
30+
*/
31+
cellFocusable?: boolean;
2832
/** The date that is focused when the calendar first mounts (uncontrolled). */
2933
defaultFocusedValue?: DateTime;
3034
/** Handler that is called when the focused date changes. */

src/components/CalendarView/hooks/useCalendarState.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ export function useCalendarState(props: CalendarStateOptions): CalendarState {
4646
);
4747
const timeZone = props.timeZone || inputTimeZone;
4848

49+
const cellFocusable = props.cellFocusable ?? true;
50+
4951
const minValue = React.useMemo(
5052
() => (props.minValue ? props.minValue.timeZone(timeZone) : undefined),
5153
[timeZone, props.minValue],
@@ -225,7 +227,12 @@ export function useCalendarState(props: CalendarStateOptions): CalendarState {
225227
}
226228
},
227229
isCellFocused(date: DateTime) {
228-
return this.isFocused && focusedDate && date.isSame(focusedDate, currentMode);
230+
return (
231+
cellFocusable &&
232+
this.isFocused &&
233+
focusedDate &&
234+
date.isSame(focusedDate, currentMode)
235+
);
229236
},
230237
isCellDisabled(date: DateTime) {
231238
return this.disabled || this.isInvalid(date);

0 commit comments

Comments
 (0)