Skip to content

Commit

Permalink
Merge pull request #3727 from carbon-design-system/fix-3620
Browse files Browse the repository at this point in the history
fix(datetimepickerv2): flyout menu change position to left-start when set --wrapper-width to 100%
  • Loading branch information
kodiakhq[bot] authored Mar 9, 2023
2 parents 0291e75 + a24452c commit bb394af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2078,7 +2078,7 @@ describe('DateTimePickerV2', () => {
Element.prototype.getBoundingClientRect = originalGetBoundingClientRect;
});

it('when flyout offscreen top right render direction to LeftStart', () => {
it('when flyout offscreen top right render direction to bottomEnd', () => {
const originalGetBoundingClientRect = Element.prototype.getBoundingClientRect;
const mockGetBoundingClientRect = jest.fn(
generateBoundingClientRect({
Expand Down Expand Up @@ -2123,7 +2123,7 @@ describe('DateTimePickerV2', () => {
const menu = screen.getByTestId(`${testId}-datepicker-flyout`);

expect(
menu.classList.contains(`${iotPrefix}--flyout-menu--body__${FlyoutMenuDirection.LeftStart}`)
menu.classList.contains(`${iotPrefix}--flyout-menu--body__${FlyoutMenuDirection.BottomEnd}`)
).toBe(true);
Element.prototype.getBoundingClientRect = originalGetBoundingClientRect;
});
Expand Down Expand Up @@ -2323,7 +2323,7 @@ describe('DateTimePickerV2', () => {
const menu = screen.getByTestId(`${testId}-datepicker-flyout`);

expect(
menu.classList.contains(`${iotPrefix}--flyout-menu--body__${FlyoutMenuDirection.LeftEnd}`)
menu.classList.contains(`${iotPrefix}--flyout-menu--body__${FlyoutMenuDirection.BottomEnd}`)
).toBe(true);
Element.prototype.getBoundingClientRect = originalGetBoundingClientRect;
});
Expand Down
5 changes: 4 additions & 1 deletion packages/react/src/hooks/usePopoverPositioning.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ export const usePopoverPositioning = ({
break;
case 'right':
case 'top-right':
if (direction === 'bottom-end') {
break;
}
if (flyoutAlignment) {
// fixes an edge case where if the flyout is right-end,
// and causes an overflow to the top-right, then we need to
Expand Down Expand Up @@ -340,7 +343,7 @@ export const usePopoverPositioning = ({
left: newOffset.left + adjustedOffset.left,
};
},
[adjustedDirection, flyoutAlignment, getAdjustedOffset, getOffset, isOverflowMenu]
[adjustedDirection, direction, flyoutAlignment, getAdjustedOffset, getOffset, isOverflowMenu]
);

/**
Expand Down

0 comments on commit bb394af

Please sign in to comment.