Skip to content
Open
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
21 changes: 19 additions & 2 deletions packages/react/src/components/DatePicker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,23 @@ const DatePicker = React.forwardRef(function DatePicker(

const { current: start } = startInputField;
const { current: end } = endInputField;

// Auto-detect if DatePicker is in a modal and use appendTo for proper positioning
let effectiveAppendTo = appendTo;
if (!effectiveAppendTo && start) {
// Check if the input is inside a modal
const modalElement = start.closest(`.${prefix}--modal`);
if (modalElement) {
// Find the modal container to append the calendar to
const modalContainer = modalElement.querySelector(
`.${prefix}--modal-container`
);
if (modalContainer) {
effectiveAppendTo = modalContainer as HTMLElement;
}
}
}
Comment on lines +668 to +682
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few concerns:

  1. This change appears to target only modals. Are you certain the issue is limited to modals?
  2. This functionality relies on class selectors. Is there a more robust way to target modals than using class names? I have the same concern regarding the changes in Modal.tsx.


// eslint-disable-next-line @typescript-eslint/no-explicit-any -- https://github.com/carbon-design-system/carbon/issues/20452
const flatpickerConfig: any = {
inline: inline ?? false,
Expand All @@ -685,9 +702,9 @@ const DatePicker = React.forwardRef(function DatePicker(
input: endInputField.current ?? undefined,
})
: () => {},
appendTo
effectiveAppendTo
? appendToPlugin({
appendTo,
appendTo: effectiveAppendTo,
})
: () => {},
carbonFlatpickrMonthSelectPlugin({
Expand Down
4 changes: 4 additions & 0 deletions packages/react/src/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,10 @@ const ModalDialog = React.forwardRef(function ModalDialog(
return;
}

if (currentActiveNode.classList.contains(`${prefix}--date-picker__input`)) {
return;
}

currentActiveNode.scrollIntoView({ block: 'center' });
}

Expand Down
Loading