From b4a47f1fad871e020a5a6068965a8018b7b9149d Mon Sep 17 00:00:00 2001 From: XUE YAN Date: Tue, 21 Feb 2023 14:53:23 -0600 Subject: [PATCH] fix(datetimepickerv2): fix autoposition --- .../src/components/DateTimePicker/DateTimePickerV2.test.jsx | 6 +++--- packages/react/src/hooks/usePopoverPositioning.jsx | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/react/src/components/DateTimePicker/DateTimePickerV2.test.jsx b/packages/react/src/components/DateTimePicker/DateTimePickerV2.test.jsx index df8fb6fc13..d8c44a57c4 100644 --- a/packages/react/src/components/DateTimePicker/DateTimePickerV2.test.jsx +++ b/packages/react/src/components/DateTimePicker/DateTimePickerV2.test.jsx @@ -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({ @@ -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; }); @@ -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; }); diff --git a/packages/react/src/hooks/usePopoverPositioning.jsx b/packages/react/src/hooks/usePopoverPositioning.jsx index ea7d193a6a..d02cf93fd3 100644 --- a/packages/react/src/hooks/usePopoverPositioning.jsx +++ b/packages/react/src/hooks/usePopoverPositioning.jsx @@ -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 @@ -340,7 +343,7 @@ export const usePopoverPositioning = ({ left: newOffset.left + adjustedOffset.left, }; }, - [adjustedDirection, flyoutAlignment, getAdjustedOffset, getOffset, isOverflowMenu] + [adjustedDirection, direction, flyoutAlignment, getAdjustedOffset, getOffset, isOverflowMenu] ); /**