@@ -9,6 +9,7 @@ import {block} from '../../utils/cn';
99import type { Value } from '../RelativeDatePicker' ;
1010import type {
1111 DomProps ,
12+ FocusableProps ,
1213 InputBase ,
1314 RangeValue ,
1415 StyleProps ,
@@ -35,6 +36,7 @@ export interface RelativeRangeDatePickerProps
3536 InputBase ,
3637 TextInputProps ,
3738 Validation ,
39+ FocusableProps ,
3840 StyleProps {
3941 /** Format of the date when rendered in the input. [Available formats](https://day.js.org/docs/en/display/format) */
4042 format ?: string ;
@@ -70,16 +72,26 @@ export function RelativeRangeDatePicker(props: RelativeRangeDatePickerProps) {
7072 const [ open , setOpen ] = React . useState ( false ) ;
7173
7274 const { focusWithinProps} = useFocusWithin ( {
73- isDisabled : props . disabled || isMobile ,
74- onFocusWithinChange : ( isFocusedWithin ) => {
75- if ( ! isFocusedWithin ) {
75+ isDisabled : props . disabled ,
76+ onFocusWithin : ( e ) => {
77+ if ( ! isActive ) {
78+ props . onFocus ?.( e ) ;
79+ }
80+ } ,
81+ onBlurWithin : ( e ) => {
82+ // when the popup is open and an user clicks outside, focus will be returned to the input
83+ const seemsIsClickOutsideInEmptySpace =
84+ open &&
85+ ( document . activeElement === null || document . activeElement === document . body ) ;
86+ if ( ! seemsIsClickOutsideInEmptySpace ) {
7687 setIsActive ( false ) ;
88+ props . onBlur ?.( e ) ;
7789 }
7890 } ,
7991 } ) ;
8092
8193 const { alwaysShowAsAbsolute, presetTabs, getRangeTitle} = props ;
82- const format = props . format ?? 'L' ;
94+ const format = props . format || 'L' ;
8395 const text = React . useMemo (
8496 ( ) =>
8597 typeof getRangeTitle === 'function'
@@ -116,6 +128,7 @@ export function RelativeRangeDatePicker(props: RelativeRangeDatePickerProps) {
116128 }
117129 >
118130 < TextInput
131+ autoFocus = { props . autoFocus }
119132 controlRef = { inputRef }
120133 value = { text }
121134 placeholder = { props . placeholder }
0 commit comments