Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(DatePicker): Fix compatibility with strict mode #3964

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/react-component-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@
"date-fns": "^2.9.0",
"decimal.js": "^10.3.1",
"downshift": "^6.1.12",
"focus-trap": "^6.9.0",
"focus-trap-react": "^8.11.0",
"focus-trap": "^7.6.2",
"focus-trap-react": "^10.3.1",
"lodash": "^4.17.21",
"polished": "^4.0.3",
"react-compound-slider": "^3.3.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,15 @@ export const Input = memo(

const handleInputClick = useCallback(() => {
if (isRange) {
dispatch({ type: DATEPICKER_ACTION.TOGGLE_OPEN })
dispatch({
type: DATEPICKER_ACTION.UPDATE,
data: {
calendarTableVariant: CALENDAR_TABLE_VARIANT.HIDE,
isOpen: !isOpen,
},
})
}
}, [isRange, dispatch])
}, [isOpen, isRange, dispatch])

const handleShowHideClick = useCallback(() => {
dispatch({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const DATEPICKER_ACTION = {
UPDATE: 'UPDATE',
REFRESH_HAS_ERROR: 'REFRESH_HAS_ERROR',
REFRESH_INPUT_VALUE: 'REFRESH_INPUT_VALUE',
TOGGLE_OPEN: 'TOGGLE_OPEN',
} as const

interface ResetAction {
Expand All @@ -39,14 +38,8 @@ interface RefreshInputValueAction {
data?: never
}

interface ToggleOpenAction {
type: typeof DATEPICKER_ACTION.TOGGLE_OPEN
data?: never
}

export type DatePickerAction =
| ResetAction
| UpdateAction
| RefreshHasErrorAction
| RefreshInputValueAction
| ToggleOpenAction
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ function reducer(
state.datePickerFormat
),
}
case DATEPICKER_ACTION.TOGGLE_OPEN:
return {
...state,
isOpen: !state.isOpen,
}
default:
throw new Error('Unknown reducer action type')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,21 @@ export function useFocusTrapOptions(
() => ({
allowOutsideClick: (event) =>
isEventTargetDescendantOf(event, clickAllowedElementRefs),
clickOutsideDeactivates: (event) =>
!isEventTargetDescendantOf(event, clickAllowedElementRefs),
clickOutsideDeactivates: (event) => {
const shouldDeactivate = !isEventTargetDescendantOf(
event,
clickAllowedElementRefs
)
if (shouldDeactivate) {
close()
}
return shouldDeactivate
},
escapeDeactivates: () => {
close()
return true
},
initialFocus: false,
onDeactivate: close,
}),
[clickAllowedElementRefs, close]
)
Expand Down
Loading
Loading