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

feat(cxl-ui): [cxl-marketing-nav] add scroll indicator for large menus #277

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions packages/cxl-ui/scss/global/cxl-marketing-nav.scss
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,14 @@ vaadin-context-menu-list-box {
display: none;
}
}

/* stylelint-disable order/properties-order */
.can-scroll {
background: linear-gradient(rgba(255, 255, 255, 0), rgba(255, 255, 255, 1));
bottom: 0;
cursor: pointer;
position: sticky;
text-align: center;
width: 100%;
}
/* stylelint-enable order/properties-order */
45 changes: 36 additions & 9 deletions packages/cxl-ui/src/components/cxl-marketing-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,23 +235,21 @@ export class CXLMarketingNavElement extends LitElement {
*/
_onOverlayOpen(e) {
const overlay = e.target;
const overlays = document.querySelectorAll(
'vaadin-context-menu-overlay[theme="cxl-marketing-nav"]'
);
const topLevelOverlay = overlays[0];
const listBox = overlay.querySelector('vaadin-context-menu-list-box');
const previousOverlay = overlays[overlays.length - 2];
const previousListBox = previousOverlay.querySelector('vaadin-context-menu-list-box');

/**
* Vertically align context menu panels.
* Check if the child overlay is larger than the top level overlay.
*
* @since 2023.02.11
*/
const overlays = document.querySelectorAll(
'vaadin-context-menu-overlay[theme="cxl-marketing-nav"]'
);

if (overlays.length > 1) {
const topLevelOverlay = overlays[0];
const listBox = overlay.querySelector('vaadin-context-menu-list-box');
const previousOverlay = overlays[overlays.length - 2];
const previousListBox = previousOverlay.querySelector('vaadin-context-menu-list-box');

requestAnimationFrame(() => {
if (listBox.offsetHeight > previousListBox.offsetHeight) {
overlay.style.top = topLevelOverlay.style.top;
Expand All @@ -269,6 +267,35 @@ export class CXLMarketingNavElement extends LitElement {
}

this.submenuOverlay = overlay;

/**
* Add a scroll indicator to let the user know that there are more items in the list.
*
* @since 2023.05.01
* @see https://app.clickup.com/t/861mkj72q
*/

// Make sure we are on a desktop
if (this.wide) {
const canScroll = overlay.querySelector('.can-scroll');

// Remove the scroll indicator if it exists
if (canScroll) {
overlay.removeChild(canScroll);
}

if (listBox.offsetHeight > overlay.offsetHeight) {
const menuItem = document.createElement('vaadin-context-menu-item');
menuItem.classList.add('can-scroll');

menuItem.addEventListener('click', () => {
overlay.shadowRoot.querySelector('[part="overlay"]').scrollTop += 100;
});

render(html`<vaadin-icon icon="lumo:angle-down"></vaadin-icon>`, menuItem);
overlay.appendChild(menuItem);
}
}
}

/**
Expand Down