A platform for community discussion. Free, open, simple.
UX: add scrollable hints (blur/caret) to composer toolbar (#38157)
Renato Atilio9eb5fa0c0a38
diff --git a/app/assets/stylesheets/common/d-editor.scss b/app/assets/stylesheets/common/d-editor.scssindex 727bd325ca2..3428a058cfb 100644--- a/app/assets/stylesheets/common/d-editor.scss+++ b/app/assets/stylesheets/common/d-editor.scss@@ -312,25 +312,85 @@}}-// d-editor bar button sizing+.d-editor-button-bar__wrap {+ position: relative;+ min-width: 0;+ margin-left: 1px;+ margin-right: 1px;+}++.d-editor-button-bar__scroll-btn {+ --fade-width: 2rem;+ --fade-color: var(--secondary);+ position: absolute;+ top: 0;+ bottom: 0;+ z-index: 2;+ background: var(--fade-color);+ border: none;+ padding: 0 var(--space-1);+ margin-block: 1px;+ display: flex;+ align-items: center;+ cursor: pointer;+ color: var(--primary-high);++ .discourse-touch & {+ width: 0;+ padding: 0;+ overflow: visible;+ pointer-events: none;+ color: transparent;+ }++ .discourse-no-touch &:hover {+ color: var(--primary);+ }++ &.--left {+ left: 0;++ &::after {+ content: "";+ position: absolute;+ left: 100%;+ height: 100%;+ width: var(--fade-width);+ background: linear-gradient(to right, var(--fade-color), transparent);+ pointer-events: none;+ }+ }++ &.--right {+ right: 0;++ &::before {+ content: "";+ position: absolute;+ right: 100%;+ height: 100%;+ width: var(--fade-width);+ background: linear-gradient(to left, var(--fade-color), transparent);+ pointer-events: none;+ }+ }+}+.d-editor-button-bar {display: flex;flex-direction: row;- flex-wrap: wrap;+ flex-wrap: nowrap;gap: var(--space-2);- margin: 0.25rem 0;-- @include viewport.until(sm) {- flex-wrap: nowrap;- padding-block: var(--space-1);- overflow-x: auto;- scrollbar-width: none;- -ms-overflow-style: none;- max-width: 100%;+ margin: 0;+ padding-block: var(--space-1);+ overflow-x: auto;+ overflow-y: hidden;+ scrollbar-width: none;+ -ms-overflow-style: none;+ max-width: 100%;- &::-webkit-scrollbar {- display: none;- }+ &::-webkit-scrollbar {+ display: none;}.btn:focus-visible {@@ -366,7 +426,6 @@&.--replaced-toolbar {animation: float-left ease 0.2s 1 forwards;- flex-wrap: nowrap;@keyframes float-left {0% {diff --git a/frontend/discourse/app/components/composer/toolbar-scroll-container.gjs b/frontend/discourse/app/components/composer/toolbar-scroll-container.gjsnew file mode 100644index 00000000000..7561e0cfcfb--- /dev/null+++ b/frontend/discourse/app/components/composer/toolbar-scroll-container.gjs@@ -0,0 +1,100 @@+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { on } from "@ember/modifier";+import { action } from "@ember/object";+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 onResize from "discourse/modifiers/on-resize";++export default class ToolbarScrollContainer extends Component {+ @tracked hasLeftScroll = false;+ @tracked hasRightScroll = false;+ scrollable = null;++ @action+ setup(element) {+ this.scrollable = element;+ this.checkScroll(element);+ }++ @bind+ onResize(entries) {+ this.checkScroll(entries[0].target);+ }++ @action+ onScroll(event) {+ this.checkScroll(event.target);+ }++ checkScroll(element) {+ const { scrollWidth, scrollLeft, offsetWidth } = element;+ const hasOverflow = scrollWidth > offsetWidth;+ this.hasLeftScroll = hasOverflow && scrollLeft > 2;+ this.hasRightScroll =+ hasOverflow && scrollWidth - scrollLeft - offsetWidth > 2;+ }++ @action+ scrollLeft() {+ this.scrollable?.scrollBy({+ left: -this.scrollable.offsetWidth,+ behavior: "smooth",+ });+ }++ @action+ scrollRight() {+ this.scrollable?.scrollBy({+ left: this.scrollable.offsetWidth,+ behavior: "smooth",+ });+ }++ @action+ preventFocusGrab(event) {+ event.preventDefault();+ }++ <template>+ <div class="d-editor-button-bar__wrap">+ {{#if this.hasLeftScroll}}+ {{! template-lint-disable no-pointer-down-event-binding }}+ <button+ type="button"+ class="d-editor-button-bar__scroll-btn --left"+ tabindex="-1"+ {{on "mousedown" this.preventFocusGrab}}+ {{on "click" this.scrollLeft}}+ >+ {{icon "chevron-left"}}+ </button>+ {{/if}}++ <div+ class={{concatClass "d-editor-button-bar" @class}}+ role="toolbar"+ {{didInsert this.setup}}+ {{onResize this.onResize}}+ {{on "scroll" this.onScroll}}+ >+ {{yield}}+ </div>++ {{#if this.hasRightScroll}}+ {{! template-lint-disable no-pointer-down-event-binding }}+ <button+ type="button"+ class="d-editor-button-bar__scroll-btn --right"+ tabindex="-1"+ {{on "mousedown" this.preventFocusGrab}}+ {{on "click" this.scrollRight}}+ >+ {{icon "chevron-right"}}+ </button>+ {{/if}}+ </div>+ </template>+}diff --git a/frontend/discourse/app/components/d-editor.gjs b/frontend/discourse/app/components/d-editor.gjsindex 82cdc77657d..2343da605cd 100644--- a/frontend/discourse/app/components/d-editor.gjs+++ b/frontend/discourse/app/components/d-editor.gjs@@ -16,6 +16,7 @@ import { Promise } from "rsvp";import TextareaEditor from "discourse/components/composer/textarea-editor";import ToggleSwitch from "discourse/components/composer/toggle-switch";import ToolbarButtons from "discourse/components/composer/toolbar-buttons";+import ToolbarScrollContainer from "discourse/components/composer/toolbar-scroll-container";import ConditionalLoadingSpinner from "discourse/components/conditional-loading-spinner";import DButton from "discourse/components/d-button";import DEditorPreview from "discourse/components/d-editor-preview";@@ -783,7 +784,7 @@ export default class DEditor extends Component {>{{#if this.replacedToolbarInstance}}- <div class="d-editor-button-bar --replaced-toolbar" role="toolbar">+ <ToolbarScrollContainer @class="--replaced-toolbar"><DButton@action={{this.resetToolbar}}@icon="angle-left"@@ -796,9 +797,9 @@ export default class DEditor extends Component {@rovingButtonBar={{this.rovingButtonBar}}@isFirst={{false}}/>- </div>+ </ToolbarScrollContainer>{{else}}- <div class="d-editor-button-bar" role="toolbar">+ <ToolbarScrollContainer>{{#if this.showEditorModeToggle}}<ToggleSwitch@preventFocus={{true}}@@ -814,7 +815,7 @@ export default class DEditor extends Component {@rovingButtonBar={{this.rovingButtonBar}}@isFirst={{not this.siteSettings.rich_editor}}/>- </div>+ </ToolbarScrollContainer>{{/if}}<ConditionalLoadingSpinner @condition={{this.loading}} />