Skip to content

A platform for community discussion. Free, open, simple.

UX: improve scroll-ability visual feedback in toolbar menu (#38549)

Renato Atilio83aee505158c
diff --git a/app/assets/stylesheets/common/toolbar-popup-menu-options.scss b/app/assets/stylesheets/common/toolbar-popup-menu-options.scss
index 42134f8c1fa..ea407481f2c 100644
--- a/app/assets/stylesheets/common/toolbar-popup-menu-options.scss
+++ b/app/assets/stylesheets/common/toolbar-popup-menu-options.scss
@@ -12,23 +12,39 @@
.fk-d-menu__inner-content {
flex-direction: column;
- }
- &.--scrollable .fk-d-menu__inner-content {
- --fade-height: 2em;
+ --fade-height: 2.5em;
+ &::before,
&::after {
content: "";
position: sticky;
- bottom: 0;
+ display: block;
flex-shrink: 0;
height: var(--fade-height);
- margin-top: calc(var(--fade-height) * -1);
pointer-events: none;
+ opacity: 0;
+ z-index: 1;
+ }
+
+ &::before {
+ top: 0;
+ margin-bottom: calc(var(--fade-height) * -1);
+ background: linear-gradient(to top, transparent, var(--secondary));
+ }
+
+ &::after {
+ bottom: 0;
+ margin-top: calc(var(--fade-height) * -1);
background: linear-gradient(to bottom, transparent, var(--secondary));
}
}
+ &.--scroll-top .fk-d-menu__inner-content::before,
+ &.--scroll-bottom .fk-d-menu__inner-content::after {
+ opacity: 1;
+ }
+
.fullscreen-composer & {
z-index: z("header") + 1;
}
@@ -44,6 +60,7 @@
&.--apple {
letter-spacing: 0.25em;
+ padding-right: 0.35em;
}
@include viewport.until(sm) {
diff --git a/frontend/discourse/app/components/toolbar-popup-menu-options.gjs b/frontend/discourse/app/components/toolbar-popup-menu-options.gjs
index ddeb913b585..c476f8fff13 100644
--- a/frontend/discourse/app/components/toolbar-popup-menu-options.gjs
+++ b/frontend/discourse/app/components/toolbar-popup-menu-options.gjs
@@ -24,18 +24,28 @@ export default class ToolbarPopupMenuOptions extends Component {
return;
}
- const checkScrollable = () => {
+ const checkScroll = () => {
+ const { scrollHeight, scrollTop, clientHeight } = innerContent;
+ const hasOverflow = scrollHeight > clientHeight;
menuElement.classList.toggle(
- "--scrollable",
- innerContent.scrollHeight > innerContent.clientHeight
+ "--scroll-top",
+ hasOverflow && scrollTop > 2
+ );
+ menuElement.classList.toggle(
+ "--scroll-bottom",
+ hasOverflow && scrollHeight - scrollTop - clientHeight > 2
);
};
- const observer = new ResizeObserver(checkScrollable);
+ const observer = new ResizeObserver(checkScroll);
observer.observe(innerContent);
- checkScrollable();
+ innerContent.addEventListener("scroll", checkScroll, { passive: true });
+ checkScroll();
- return () => observer.disconnect();
+ return () => {
+ observer.disconnect();
+ innerContent.removeEventListener("scroll", checkScroll);
+ };
});
willDestroy() {
diff --git a/frontend/discourse/tests/integration/components/toolbar-popup-menu-options-test.gjs b/frontend/discourse/tests/integration/components/toolbar-popup-menu-options-test.gjs
index 4642cfefa78..ccc6e499e7f 100644
--- a/frontend/discourse/tests/integration/components/toolbar-popup-menu-options-test.gjs
+++ b/frontend/discourse/tests/integration/components/toolbar-popup-menu-options-test.gjs
@@ -19,7 +19,7 @@ module(
function (hooks) {
setupRenderingTest(hooks);
- test("adds --scrollable class when content overflows", async function (assert) {
+ test("adds scroll classes when content overflows", async function (assert) {
const content = generateOptions(30);
await render(
@@ -37,10 +37,12 @@ module(
await click(".fk-d-menu__trigger");
- assert.dom(".fk-d-menu[class*='toolbar-menu']").hasClass("--scrollable");
+ const menu = document.querySelector(".fk-d-menu[class*='toolbar-menu']");
+ assert.false(menu.classList.contains("--scroll-top"));
+ assert.true(menu.classList.contains("--scroll-bottom"));
});
- test("does not add --scrollable class when content fits", async function (assert) {
+ test("does not add scroll classes when content fits", async function (assert) {
const content = generateOptions(2);
await render(
@@ -58,9 +60,9 @@ module(
await click(".fk-d-menu__trigger");
- assert
- .dom(".fk-d-menu[class*='toolbar-menu']")
- .doesNotHaveClass("--scrollable");
+ const menu = document.querySelector(".fk-d-menu[class*='toolbar-menu']");
+ assert.false(menu.classList.contains("--scroll-top"));
+ assert.false(menu.classList.contains("--scroll-bottom"));
});
}
);