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

Add block-start and block-end positioning to PopoverMixin #5125

Merged
merged 16 commits into from
Nov 29, 2024

Conversation

dbatiste
Copy link
Contributor

@dbatiste dbatiste commented Oct 31, 2024

GAUD-6456 (positioning)
GAUD-7121 (sizing)
GAUD-7120 (pointer)

This PR adds block-start (above) and block-end (end) positioning to the PopoverMixin. The fixed positioning logic was adapted from DropdownContentMixin. It also adds sizing logic since that's necessary for the positioning calculations.

It does not include inline-start (left) and inline-end (right) positioning. That will be added in a future PR.

The PopoverMixin demo is not in our index.html. Here is a link to it.

@dbatiste dbatiste requested a review from a team as a code owner October 31, 2024 17:55
Copy link
Contributor

Thanks for the PR! 🎉

We've deployed an automatic preview for this PR - you can see your changes here:

URL https://live.d2l.dev/prs/BrightspaceUI/core/pr-5125/

Note

The build needs to finish before your changes are deployed.
Changes to the PR will automatically update the instance.

dbatiste and others added 3 commits October 31, 2024 14:25
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@dbatiste
Copy link
Contributor Author

dbatiste commented Nov 1, 2024

If possible, I would like to build out the visual-diffs in a separate PR.

@@ -53,14 +73,56 @@ export const PopoverMixin = superclass => class extends superclass {
:host([_opened]) {
display: inline-block;
}
:host([_location="block-start"]) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These logical positioning terms are being used to align more closely with what the browser is doing, as well as to set us up for supporting other locations.
block-start -> top (this PR)
block-end -> bottom (this PR)
inline-start -> left (future PR)
inline-end -> right (future PR)

}

.pointer {
clip: rect(-5px, 21px, 8px, -7px);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We were able to ditch some old pointer CSS with our fixed positioning. 🎉

@@ -72,26 +134,37 @@ export const PopoverMixin = superclass => class extends superclass {
animation: var(--d2l-popover-animation-name, var(--d2l-popover-default-animation-name)) 300ms ease;
}
}

:host([_offscreen]) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As with fixed position dropdown, we position offscreen when the opener is scrolled out of view.

}

_clearDismissible() {
#addRepositionHandlers() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code is basically copied from DropdownContentMixin. The only real difference is that we need to handle the opener IntersectionObserver here, since the opener could literally be any element, as compared to dropdown, where we do this wire-up in DropdownOpenerMixin.

if (!this._dismissibleId) return;
clearDismissible(this._dismissibleId);
this._dismissibleId = null;
}

_focusContent(container) {
#constrainSpaceAround(spaceAround, spaceRequired, openerRect) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is basically adapted from DropdownContentMixin, except the boundary constraints aren't included here (yet), and align is changed to position span to align with what the browser is doing for positioning in the logical 3x3 grid.

return this.shadowRoot.querySelector('.content-container');
}

#getLocation(spaceAround, spaceAroundScroll, spaceRequired) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method basically defines where we will place the popover based on the specified preferred location, based on the space available in the viewport and document.

return this.shadowRoot.querySelector('.pointer');
}

#getPointerPosition(openerRect) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This logic is almost exactly the same as DropdownContentMixin but I adjusted the calculation for the RTL align/span cases since I noticed they were not working quite right.

return position;
}

#getPosition(spaceAround, openerRect, contentRect) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This logic is the same as DropdownContentMixin, with some renaming.

return position;
}

#getPositionXAdjustment(spaceAround, openerRect, contentRect) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This logic is the same as DropdownContentMixin with some renaming.

}

_renderPopover() {
const content = html`<div class="content"><slot></slot></div>`;
async #position(contentRect, options) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This logic is the same as DropdownContentMixin with some renaming. Was also nice to ditch the non-fixed positioning logic.

components/popover/popover-mixin.js Outdated Show resolved Hide resolved
components/popover/popover-mixin.js Outdated Show resolved Hide resolved
components/popover/popover-mixin.js Show resolved Hide resolved
@dbatiste dbatiste merged commit 900705e into main Nov 29, 2024
6 checks passed
@dbatiste dbatiste deleted the dbatiste/popover-positioning branch November 29, 2024 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants