@@ -22,7 +22,8 @@ import {useRef} from 'react';
2222 * A range calendar displays one or more date grids and allows users to select a contiguous range of dates.
2323 */
2424export function useRangeCalendar < T extends DateValue > ( props : AriaRangeCalendarProps < T > , state : RangeCalendarState , ref : RefObject < FocusableElement | null > ) : CalendarAria {
25- let res = useCalendarBase ( props , state ) ;
25+ let { pointerUpOutsideAction = 'select' , ...otherProps } = props ;
26+ let res = useCalendarBase ( otherProps , state ) ;
2627
2728 // We need to ignore virtual pointer events from VoiceOver due to these bugs.
2829 // https://bugs.webkit.org/show_bug.cgi?id=222627
@@ -36,7 +37,13 @@ export function useRangeCalendar<T extends DateValue>(props: AriaRangeCalendarPr
3637 isVirtualClick . current = e . width === 0 && e . height === 0 ;
3738 } ) ;
3839
39- // Stop range selection when pressing or releasing a pointer outside the calendar body,
40+ const pointerUpOutsideActionMapping = {
41+ clear : ( ) => state . clearSelection ( ) ,
42+ reset : ( ) => state . setAnchorDate ( null ) ,
43+ select : ( ) => state . selectFocusedDate ( )
44+ } ;
45+
46+ // Execute method corresponding to `pointerUpOutsideAction` when pressing or releasing a pointer outside the calendar body,
4047 // except when pressing the next or previous buttons to switch months.
4148 let endDragging = ( e : PointerEvent ) => {
4249 if ( isVirtualClick . current ) {
@@ -55,19 +62,20 @@ export function useRangeCalendar<T extends DateValue>(props: AriaRangeCalendarPr
5562 ref . current . contains ( document . activeElement ) &&
5663 ( ! ref . current . contains ( target ) || ! target . closest ( 'button, [role="button"]' ) )
5764 ) {
58- state . selectFocusedDate ( ) ;
65+ pointerUpOutsideActionMapping [ pointerUpOutsideAction ] ( ) ;
5966 }
6067 } ;
6168
6269 useEvent ( windowRef , 'pointerup' , endDragging ) ;
6370
64- // Also stop range selection on blur, e.g. tabbing away from the calendar.
71+ // Also execute method corresponding to `pointerUpOutsideAction` on blur,
72+ // e.g. tabbing away from the calendar.
6573 res . calendarProps . onBlur = e => {
6674 if ( ! ref . current ) {
6775 return ;
6876 }
6977 if ( ( ! e . relatedTarget || ! ref . current . contains ( e . relatedTarget ) ) && state . anchorDate ) {
70- state . selectFocusedDate ( ) ;
78+ pointerUpOutsideActionMapping [ pointerUpOutsideAction ] ( ) ;
7179 }
7280 } ;
7381
0 commit comments