-
Notifications
You must be signed in to change notification settings - Fork 82
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
feat(dropdown): use Popper.js for a proper positioning #597
Conversation
Deploy preview for forma-36-react-components ready! Built with commit 20880fb https://deploy-preview-597--forma-36-react-components.netlify.app |
Deploy preview for forma-36-react-components ready! Built with commit 4651b47 https://deploy-preview-597--forma-36-react-components.netlify.app |
9a1bc38
to
d583c96
Compare
Awesome 😻, looks like there are some issues with the
|
This comment has been minimized.
This comment has been minimized.
4dd2a37
to
f31379e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work
6f03ad8
to
4cb1c5a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
styles[`DropdownContainer__container-position--${this.state.position}`], | ||
); | ||
return () => { | ||
document.body.removeChild(portalTarget.current); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should refactor the Tooltip to use Portals as well. But In another PR of course 😄
@@ -18,7 +18,6 @@ function DefaultStory() { | |||
onClose={() => setOpen(false)} | |||
isFullWidth={boolean('isFullWidth', false)} | |||
key={Date.now()} // Force Reinit | |||
isAutoalignmentEnabled={boolean('isAutoalignmentEnabled', true)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to refactor it to the new format, but we can totally do it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Great work!
As you are removing isAutoalignmentEnabled
would this mean minor change in the API?
On a separate PR we could do refactor to the story to new storybook format and add README for the component. But we can totally do it later.
Overall great! 🙌
4cb1c5a
to
213ecf0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you are removing isAutoalignmentEnabled would this mean minor change in the API?
This is kind of a breaking change in the sense that previously you could disable auto-alignment explicitly via isAutoalignmentEnabled={false}
. If you rely on this behavior for some reason it's breaking for you.
@denkristoffer Searching for "isAutoalignmentEnabled" I noticed that we're relying on this in the web app in two places. If you really want to remove this prop, please make sure it's not strictly necessary there and that the UI around it still works fine without it.
@denkristoffer if this means breaking change, I think we should w8 and group this with other changes to release bigger major version. We have couple of things - We could move some of the alpha components to main build I think and I'm sure that we have couple of more things that might do into the next major release. Maybe a catch up regarding this topic would be a good thing to do? WDYT? |
This comment has been minimized.
This comment has been minimized.
213ecf0
to
8a86e31
Compare
@burakukula @DanweDE I think I managed to replicate disabling positioning with the |
const { submenu, className, width, testId } = this.props; | ||
useEffect(() => { | ||
if (isOpen) { | ||
document.body.appendChild(portalTarget.current); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@denkristoffer if you can find a way to not to use portal it would be awesome. the problem with portal is keyboard focus order; upon open the dropdown content is at the end of the document, onClose the next keyboard element to be focused is the first element in the document. I hope that makes any sense, let's talk about it if not :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mshaaban0 I agree, the portal should be removed by default. I think we should handle this separately in #601 though, also to make sure this PR doesn't break any existing uses of the dropdown. Is that okay with you?
6db8d89
to
77e3f65
Compare
@denkristoffer ok, cool. 😎 |
77e3f65
to
14acbdc
Compare
@burakukula Of course not 🙂 The prop is being used in the Dropdown component where Popper is used, instead of the DropdownContainer where it was used before: https://github.com/contentful/forma-36/blob/dropdown-popper/packages/forma-36-react-components/src/components/Dropdown/Dropdown.tsx#L149-L164 I've also added it back to the story. |
14acbdc
to
114d0bb
Compare
@denkristoffer super, thx! (the file was folded from me 😑 and I didn't see this change. sorry for confusion) |
testId: 'cf-ui-dropdown-portal', | ||
position: 'bottom-left', | ||
submenu: false, | ||
isAutoalignmentEnabled: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@denkristoffer Since you made the prop work again, I think you'd want to keep the default value of true
for this prop and also add it back to the DropdownContainerProps
interface above, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The functionality has been moved to Dropdown.tsx
, so you shouldn't ever want/have to pass it to DropdownContainer
.
Purpose of PR
This PR refactors the Dropdown component to use Popper.js instead of the current, custom positioning calculation.
Resolves #361
Todo
toggleElement
What to do about theisAutoalignmentEnabled
prop? It doesn't serve much of a purpose with Popper doing the positioning automatically. Is it considered a breaking change to remove it?PR Checklist
readme.md
file(s)