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(datetimepickerv2): flyout menu auto positioning #3608

Merged
merged 10 commits into from
Oct 31, 2022

Conversation

jessieyan
Copy link
Collaborator

@jessieyan jessieyan commented Oct 18, 2022

Closes #3618

Summary

  • expose renderInPortal prop so that user can set it to false for some scenarios
  • expose useAutoPositioning prop to reposition flyout menu if offscreen

Change List (commits, features, bugs, etc)

  • added renderInPortal prop in DateTimePickerV2, Card, TableCard, CardToolBar

  • added useAutoPositioning prop in DateTimePickerV2

  • fixed the menuOffSet when useAutoPositioning is enabled and in RTL. The passed-in menuOffset prop only works for the passed-in direction prop. If repositioned, the direction will be changed, menuOffset no long apply to the new direction
    before:
    image
    after:
    image

  • fixed the menuOffSet.left. set it to 288px in RTL
    Before,
    image

After:
image

  • added tests for the scenarios when using useAutoPositioning and renderInPortal
  • added a knob useAutoPositioning in single select and range select stories.

Acceptance Test (how to verify the PR)

  • go to single select story
  • deselect padding on story-container
  • add margin-left to -1rem or so to make it offscreen on the left
  • click to open flyout menu, make sure flyout menu are with in screen
    image

image

  • go to range select or single select story

  • set renderInPortal to false, we should see flyout-tooltip is grandchild of date-time-picker-datepicker-flyout-container
    image

  • set renderInPortal to true, flyout-tooltip is independent element outside of date-time-picker-datepicker-flyout-container
    image

Things to look for during review

  • Make sure all references to iot or bx class prefix is using the prefix variable
  • (React) All major areas have a data-testid attribute. New test ids should have test written to ensure they are not changed or removed.
  • UI should be checked in RTL mode to ensure the proper handling of layout and text.
  • All strings should be translatable.
  • The code should pass a11y scans (The storybook a11y knob should show no violations). New components should have a11y test written.
  • Unit test should be written and should have a coverage of 90% or higher in all areas.
  • All components should be passing visual regression test. For new styles or components either a visual regression test should be written for all permutations or the base image updated.
  • Changes or new components should either write new or update existing documentation.
  • PR should link and close out an existing issue

@jessieyan jessieyan requested a review from davidicus as a code owner October 18, 2022 20:59
@netlify
Copy link

netlify bot commented Oct 18, 2022

Deploy Preview for carbon-addons-iot-react ready!

Name Link
🔨 Latest commit 18f5388
🔍 Latest deploy log https://app.netlify.com/sites/carbon-addons-iot-react/deploys/635ff2fc9d8df500085a35aa
😎 Deploy Preview https://deploy-preview-3608--carbon-addons-iot-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Oct 18, 2022

Deploy Preview for ai-apps-pal-angular ready!

Name Link
🔨 Latest commit 18f5388
🔍 Latest deploy log https://app.netlify.com/sites/ai-apps-pal-angular/deploys/635ff2fc465d820008301b29
😎 Deploy Preview https://deploy-preview-3608--ai-apps-pal-angular.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@davidicus
Copy link
Collaborator

@jessieyan This usually needs to have it rendered in a portal, in order to break out of an overflow:hidden container, like our cards we need to be able to do so and still have the dropdown stay with the trigger. We can either close the portal on scroll or adjust the offset so it scrolls with the element. We have components in the codebase that manipulate the offset that you can try to look for.

Copy link
Collaborator

@davidicus davidicus left a comment

Choose a reason for hiding this comment

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

This is not a solution to the issue that is listed for this PR

@jessieyan
Copy link
Collaborator Author

jessieyan commented Oct 19, 2022

@jessieyan This usually needs to have it rendered in a portal, in order to break out of an overflow:hidden container, like our cards we need to be able to do so and still have the dropdown stay with the trigger. We can either close the portal on scroll or adjust the offset so it scrolls with the element. We have components in the codebase that manipulate the offset that you can try to look for.

@davidicus Do you mean the offered solution in issue 3362 is not the right solution?

@davidicus
Copy link
Collaborator

We can surface a prop to allow people to render in portal or not but we need to have the dropdown not detach even when it is rendered in portal.

@jessieyan jessieyan changed the title fix(datetimepickerv2): expose renderInPortal prop to support floating menu as a child fix(datetimepickerv2): flyout menu repositioning Oct 26, 2022
@jessieyan
Copy link
Collaborator Author

@davidicus Change this PR to only resolve the issue #3618 which is to enable the auto positioning

@jessieyan jessieyan changed the title fix(datetimepickerv2): flyout menu repositioning fix(datetimepickerv2): flyout menu auto positioning Oct 27, 2022
@jessieyan
Copy link
Collaborator Author

@davidicus I saw you left a review comment earlier but I couldn't find it in the PR.

@davidicus
Copy link
Collaborator

@davidicus I saw you left a review comment earlier but I couldn't find it in the PR.

I had deleted the comment after I saw you were returning a function. Was supposed to be part of the review.

Comment on lines +2067 to +2070
button.getBoundingClientRect = generateBoundingClientRect({
x: 20,
y: 20,
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be part of the mock implementation? One line 2035 we are setting getBoundingClientRect to a jest mocked function with one value and then resetting it here (2067) to just a function that returns another value.

packages/react/src/components/Card/Card.jsx Outdated Show resolved Hide resolved
).toHaveLength(0);
});

it('should render in a portal when renderInPortal:true (new time spinner)', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the future we can probably combine these types of variations into one test and use the rerender method to rerender the component with the new prop.

});

const button = screen.getByTestId(`${testId}-datepicker-flyout-button`);
button.getBoundingClientRect = generateBoundingClientRect({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment about having this set in the mock.

});

const button = screen.getByTestId(`${testId}-datepicker-flyout-button`);
button.getBoundingClientRect = generateBoundingClientRect({
Copy link
Collaborator

Choose a reason for hiding this comment

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

same mock comment.

});

const button = screen.getByTestId(`${testId}-datepicker-flyout-button`);
button.getBoundingClientRect = generateBoundingClientRect({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment about mock in all these test. It is possible that I am not understanding what you are doing here.

@@ -67,6 +67,7 @@ const defaultProps = {
closeLabel: 'Close',
expandLabel: 'Expand to fullscreen',
},
renderInPortal: false,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prop should be more specific since it is for a child component. Should match the name of Card component prop

Copy link
Collaborator

Choose a reason for hiding this comment

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

This should match the Card prop, no?

@davidicus
Copy link
Collaborator

davidicus commented Oct 31, 2022

There is some weird positioning if you set the padding to the storybook container to push the element all the way to the end of the page and then click the dropdown. The dropdown renders on top of element but still causes more scroll. Once you click on the date picker to choose a date it jumps up to the top of the element.

I would expect this to be rendered on top when initially opened.
https://deploy-preview-3608--carbon-addons-iot-react.netlify.app/?path=/story/2-watson-iot-experimental-%E2%98%A2%EF%B8%8F-datetimepickerv2--single-select

When there is an overflow hidden on the container and the DateTimePicker dropdown is not rendered in the portal the dropdown is cut off

@davidicus
Copy link
Collaborator

Issue with Card component and the DateTimePicker in this story

This PR Next
image image

@jessieyan
Copy link
Collaborator Author

jessieyan commented Oct 31, 2022

https://deploy-preview-3608--carbon-addons-iot-react.netlify.app/?path=/story/2-watson-iot-experimental-%E2%98%A2%EF%B8%8F-datetimepickerv2--single-select

I can see if set the padding-left to 80 rem. Then a horizontal bar showed up. The flyout menu will adjust its position if the horizontal bar moves. If set padding-left to 71 rem, The flyout menu will pop up on top of the input and will not move its position.

Copy link
Collaborator

@davidicus davidicus left a comment

Choose a reason for hiding this comment

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

We can address some of the positioning issues in another PR. Can merge once checks have passed

@jessieyan
Copy link
Collaborator Author

I can see if set the padding-left to 80 rem. Then a horizontal bar showed up. The flyout menu will adjust its position if the horizontal bar moves. If set padding-left to 71 rem, The flyout menu will pop up on top of the input and will not move its position.

Opened #3620

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DateTimePicker(V2)] use prop renderInPortal and useAutoPositioning
2 participants