Skip to content

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

UX: Lay the toolbar menu shortcut out beside its label (#42992)

Sérgio Saquetim5584352c7b75
diff --git a/app/assets/stylesheets/common/toolbar-popup-menu-options.scss b/app/assets/stylesheets/common/toolbar-popup-menu-options.scss
index 2e0cd7b1d97..33826d94118 100644
--- a/app/assets/stylesheets/common/toolbar-popup-menu-options.scss
+++ b/app/assets/stylesheets/common/toolbar-popup-menu-options.scss
@@ -75,7 +75,12 @@
&.--active {
.d-button-label__active-icon {
visibility: visible;
- margin-left: auto;
+ }
+
+ // The check owns the trailing slot at rest, even for a shortcut that
+ // is otherwise always shown.
+ &:not(:hover, :focus, :focus-visible) .shortcut {
+ visibility: hidden;
}
}
@@ -83,7 +88,7 @@
&:focus,
&:focus-visible {
.shortcut {
- display: block;
+ visibility: visible;
}
.d-button-label__active-icon {
@@ -92,32 +97,29 @@
}
}
+ // The shortcut and the active check share one trailing cell: both are
+ // laid out so the row reserves their width, and only one is shown.
.d-button-label {
- position: relative;
flex: 1;
- display: flex;
+ display: grid;
+ grid-template-columns: minmax(0, 1fr) auto;
align-items: center;
- gap: var(--space-4);
- min-width: 0; // shrink if needed
-
- &__active-icon {
- visibility: hidden;
- }
+ column-gap: var(--space-4);
+ min-width: 0;
&__text {
- padding-right: var(--space-8); // extra spacing for the shortcut
+ text-align: start;
}
+ &__active-icon,
.shortcut {
- position: absolute;
- right: 0;
- top: 50%;
- transform: translateY(-50%);
- display: none;
-
- &.--always-visible {
- display: block;
- }
+ grid-area: 1 / 2;
+ justify-self: end;
+ visibility: hidden;
+ }
+
+ .shortcut.--always-visible {
+ visibility: visible;
}
}
}
diff --git a/plugins/discourse-local-dates/spec/system/toolbar_shortcut_spec.rb b/plugins/discourse-local-dates/spec/system/toolbar_shortcut_spec.rb
index 91764ef53ad..d984226e0bb 100644
--- a/plugins/discourse-local-dates/spec/system/toolbar_shortcut_spec.rb
+++ b/plugins/discourse-local-dates/spec/system/toolbar_shortcut_spec.rb
@@ -1,6 +1,8 @@
# frozen_string_literal: true
RSpec.describe "Local dates toolbar shortcut" do
+ include ThemeScreenshotMarker
+
fab!(:current_user, :admin)
let(:composer) { PageObjects::Components::Composer.new }
@@ -19,4 +21,22 @@ RSpec.describe "Local dates toolbar shortcut" do
visible: :visible,
)
end
+
+ it "lays the shortcut out beside the label instead of over it" do
+ visit "/"
+ find("#create-topic").click
+ expect(composer).to be_opened
+
+ find(".toolbar-menu__options-trigger").click
+ row = find(".toolbar-menu__options-content [data-name='local-dates']")
+ text = row.find(".d-button-label__text")
+ chip = row.find(".d-shortcut")
+
+ text_right = page.evaluate_script("arguments[0].getBoundingClientRect().right", text)
+ chip_left = page.evaluate_script("arguments[0].getBoundingClientRect().left", chip)
+
+ expect(chip_left).to be >= text_right
+
+ screenshot_marker(label: "shortcut-options-menu-at-rest", only: :desktop)
+ end
end