-
Notifications
You must be signed in to change notification settings - Fork 1k
Drop - flip drop position if part of the drop isn't visible #6611
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
Drop - flip drop position if part of the drop isn't visible #6611
Conversation
… visible and there is more room in the opposite direction
one thing I saw in the storybook is since we have |
const percentVisibleAreaBelow = | ||
100 - (targetRect.bottom / windowHeight) * 100; | ||
const alignToTop = align.top === 'top'; | ||
const switchTop = !alignToTop ? targetRect.top : targetRect.bottom; |
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.
just opinion not sure about the naming for switchTop
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.
Agree the name is confusing. I changed it to switchTarget
since this props is new target position the drop will be aligned to if we flip the drop.
// when percentVisibleAreaBelow>20%. | ||
|
||
if (windowHeight === top || percentVisibleAreaBelow <= 20) { | ||
if ( |
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.
can we add a new comment for this section
the old comment was clear but since the behavior changed just for future reference
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.
Added a comment
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.
Just a few comments but I think the direction of this approach is a good change.
Changed the story to have |
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.
A few initial comments to get started with.
} else { | ||
({ bottom } = targetRect); | ||
} | ||
bottom = alignToTop ? targetRect.bottom : targetRect.top; | ||
maxHeight = bottom; | ||
container.style.maxHeight = `${maxHeight}px`; |
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.
How come sometimes we set container.style.maxHeight
without honoring preserveHeight
? I was expecting we'd only set the style within if (!preserveHeight) {
later down.
const switchTarget = !alignToTop | ||
? targetRect.top | ||
: targetRect.bottom; | ||
top = alignToTop ? targetRect.top : targetRect.bottom; |
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.
My head is a bit confused trying to keep track of all of this. I'm wondering if there's a way to make it a bit clearer, perhaps by renaming some variables, or perhaps by restructuring the code. For instance, would it be clearer if we just checked if (align.top === 'top') {
and then put everything for that case under it and then } else {
for the other version, rather than trying to merge them together?
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.
alot cleaner 🙌 and thanks for adding comment
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.
Good work!
What does this PR do?
Changed Drop behavior to flip the drop if part of the drop isn't visible and there is more room in the opposite direction.
I also set the
responsive
prop to true by default. This aligns with what the documentation shows.Where should the reviewer start?
What testing has been done on this PR?
How should this be manually tested?
Do Jest tests follow these best practices?
screen
is used for querying.userEvent
is used in place offireEvent
.asFragment()
is used for snapshot testing.Any background context you want to provide?
What are the relevant issues?
Closes #6495
Screenshots (if appropriate)
Do the grommet docs need to be updated?
No
Should this PR be mentioned in the release notes?
Yes
Is this change backwards compatible or is it a breaking change?
Backwards compatible