A platform for community discussion. Free, open, simple.
UX: fix RTL overflow scroll in composer controls and other nav (#39141)
Kris57f9b1014612
diff --git a/app/assets/stylesheets/common/components/horizontal-overflow-nav.scss b/app/assets/stylesheets/common/components/horizontal-overflow-nav.scssindex 0bc47d062e0..a2a1d79bcc1 100644--- a/app/assets/stylesheets/common/components/horizontal-overflow-nav.scss+++ b/app/assets/stylesheets/common/components/horizontal-overflow-nav.scss@@ -56,25 +56,45 @@}.horizontal-overflow-nav__scroll-right {+ /*! rtl:ignore */right: 0;&::before {content: "";++ /*! rtl:ignore */margin-left: calc(var(--fade-width) * -1);height: 100%;width: var(--fade-width);++ /*! rtl:ignore */background: linear-gradient(to left, var(--fade-color), transparent);}++ // Undo automatic icon flip since button stays in physical position+ .rtl & .d-icon {+ transform: scaleX(1);+ }}.horizontal-overflow-nav__scroll-left {+ /*! rtl:ignore */left: 0;&::after {content: "";++ /*! rtl:ignore */margin-right: calc(var(--fade-width) * -1);height: 100%;width: var(--fade-width);++ /*! rtl:ignore */background: linear-gradient(to right, var(--fade-color), transparent);}++ // Undo automatic icon flip since button stays in physical position+ .rtl & .d-icon {+ transform: scaleX(1);+ }}diff --git a/app/assets/stylesheets/common/d-editor.scss b/app/assets/stylesheets/common/d-editor.scssindex 4fd5e298e50..9ca14891869 100644--- a/app/assets/stylesheets/common/d-editor.scss+++ b/app/assets/stylesheets/common/d-editor.scss@@ -351,31 +351,51 @@}&.--left {+ /*! rtl:ignore */left: 0;&::after {content: "";position: absolute;++ /*! rtl:ignore */left: 100%;height: 100%;width: var(--fade-width);++ /*! rtl:ignore */background: linear-gradient(to right, var(--fade-color), transparent);pointer-events: none;}++ // Undo automatic icon flip since button stays in physical position+ .rtl & .d-icon {+ transform: scaleX(1);+ }}&.--right {+ /*! rtl:ignore */right: 0;&::before {content: "";position: absolute;++ /*! rtl:ignore */right: 100%;height: 100%;width: var(--fade-width);++ /*! rtl:ignore */background: linear-gradient(to left, var(--fade-color), transparent);pointer-events: none;}++ // Undo automatic icon flip since button stays in physical position+ .rtl & .d-icon {+ transform: scaleX(1);+ }}}diff --git a/frontend/discourse/app/components/composer/toolbar-scroll-container.gjs b/frontend/discourse/app/components/composer/toolbar-scroll-container.gjsindex 7561e0cfcfb..7cf33bf8849 100644--- a/frontend/discourse/app/components/composer/toolbar-scroll-container.gjs+++ b/frontend/discourse/app/components/composer/toolbar-scroll-container.gjs@@ -6,6 +6,7 @@ import didInsert from "@ember/render-modifiers/modifiers/did-insert";import concatClass from "discourse/helpers/concat-class";import icon from "discourse/helpers/d-icon";import { bind } from "discourse/lib/decorators";+import { isDocumentRTL } from "discourse/lib/text-direction";import onResize from "discourse/modifiers/on-resize";export default class ToolbarScrollContainer extends Component {@@ -32,9 +33,19 @@ export default class ToolbarScrollContainer extends Component {checkScroll(element) {const { scrollWidth, scrollLeft, offsetWidth } = element;const hasOverflow = scrollWidth > offsetWidth;- this.hasLeftScroll = hasOverflow && scrollLeft > 2;- this.hasRightScroll =- hasOverflow && scrollWidth - scrollLeft - offsetWidth > 2;+ const canScrollBack = hasOverflow && Math.abs(scrollLeft) > 2;+ const canScrollForward =+ hasOverflow && scrollWidth - Math.abs(scrollLeft) - offsetWidth > 2;++ // Buttons stay in physical positions (rtl:ignore in CSS), but in RTL+ // the scroll direction is reversed, so swap which button shows+ if (isDocumentRTL()) {+ this.hasLeftScroll = canScrollForward;+ this.hasRightScroll = canScrollBack;+ } else {+ this.hasLeftScroll = canScrollBack;+ this.hasRightScroll = canScrollForward;+ }}@actiondiff --git a/frontend/discourse/app/components/horizontal-overflow-nav.gjs b/frontend/discourse/app/components/horizontal-overflow-nav.gjsindex 758ca0cd162..2a08b6a6f45 100644--- a/frontend/discourse/app/components/horizontal-overflow-nav.gjs+++ b/frontend/discourse/app/components/horizontal-overflow-nav.gjs@@ -7,6 +7,7 @@ import didInsert from "@ember/render-modifiers/modifiers/did-insert";import concatClass from "discourse/helpers/concat-class";import icon from "discourse/helpers/d-icon";import { bind } from "discourse/lib/decorators";+import { isDocumentRTL } from "discourse/lib/text-direction";import onResize from "discourse/modifiers/on-resize";export default class HorizontalOverflowNav extends Component {@@ -58,20 +59,28 @@ export default class HorizontalOverflowNav extends Component {// Check if the content overflowsthis.hasScroll = scrollWidth > offsetWidth;- // Ensure the right arrow disappears only when fully scrolled- if (scrollWidth - scrollLeft - offsetWidth <= 2) {+ if (!this.hasScroll) {+ this.hideLeftScroll = true;this.hideRightScroll = true;clearInterval(this.scrollInterval);+ return;+ }++ const atStart = Math.abs(scrollLeft) <= 2;+ const atEnd = scrollWidth - Math.abs(scrollLeft) - offsetWidth <= 2;++ // Buttons stay in physical positions (rtl:ignore in CSS), but in RTL+ // the scroll direction is reversed, so swap which button hides+ if (isDocumentRTL()) {+ this.hideLeftScroll = atEnd;+ this.hideRightScroll = atStart;} else {- this.hideRightScroll = false;+ this.hideLeftScroll = atStart;+ this.hideRightScroll = atEnd;}- // Ensure the left arrow disappears only when fully scrolled to the start- if (scrollLeft <= 2) {- this.hideLeftScroll = true;+ if (atStart || atEnd) {clearInterval(this.scrollInterval);- } else {- this.hideLeftScroll = false;}}