Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/css/dropdown.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,25 @@
[popover] {
position: fixed;
margin: 0;
/* padding: var(--space-1); */
min-width: 12rem;
background-color: var(--background);
border: 1px solid var(--border);
border-radius: var(--radius-medium);
box-shadow: var(--shadow-medium);
opacity: 0;
transform: translateY(-4px);
will-change: transform, opacity;
min-width: 12rem;
transition:
opacity 150ms ease-out,
transform 150ms ease-out,
display 150ms allow-discrete,
overlay 150ms allow-discrete;

&:popover-open {
opacity: 1;
transform: translateY(0);
}

@starting-style {
&:popover-open {
opacity: 0;
transform: translateY(-4px);
}
}
}
Expand Down
20 changes: 15 additions & 5 deletions src/js/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,22 @@ class OtDropdown extends OtBase {
this.#position = () => {
// Position has to be calculated and applied manually because
// popover positioning is like fixed, relative to the window.
const r = this.#trigger.getBoundingClientRect();
const m = this.#menu.getBoundingClientRect();
requestAnimationFrame(() => {
const r = this.#trigger.getBoundingClientRect();
const m = this.#menu.getBoundingClientRect();

// Flip if menu overflows viewport.
this.#menu.style.top = `${r.bottom + m.height > window.innerHeight ? r.top - m.height : r.bottom}px`;
this.#menu.style.left = `${r.left + m.width > window.innerWidth ? r.right - m.width : r.left}px`;
const top =
r.bottom + m.height > window.innerHeight
? r.top - m.height
: r.bottom;

const left =
r.left + m.width > window.innerWidth
? r.right - m.width
: r.left;

this.#menu.style.transform = `translate(${left}px, ${top}px)`;
});
};
}

Expand Down