From f3baec665829e53f3bd45719f6561cd575c13cb6 Mon Sep 17 00:00:00 2001 From: Himanshu Bhardwaj <62466768+bhardwajhimanshu2515@users.noreply.github.com> Date: Wed, 25 Nov 2026 00:29:45 +0530 Subject: [PATCH] :sparkles: Add an options button to color assets (#13189) * :sparkles: Add an options button to color assets Color assets could only be renamed, edited, duplicated or deleted from the right-click menu, which tablet users can't open. Add a three-dot options button, like the one on typography assets, that opens the same menu below the button. It shows on hover and focus, and stays visible on devices without hover. Closes #12618 AI-assisted-by: Claude Opus 5.5 * :bug: Keep the color asset options button reachable by keyboard The options button was hidden with visibility, which also takes it out of the tab order, so :focus-within could never reveal it from the keyboard. Hide it with opacity instead, so Tab reaches the button and shows it. Open the menu through one helper for both the right click and the button, so both keep clearing the selection first. AI-assisted-by: Claude Opus 5.5 * :bug: Toggle the color asset menu and fix its row and focus --------- Co-authored-by: Luis de Dios --- .../ui/workspace/sidebar/assets/colors.cljs | 44 ++++++++++++++++--- .../ui/workspace/sidebar/assets/colors.scss | 21 ++++++++- .../ui/workspace/sidebar/assets/common.cljs | 3 +- 3 files changed, 60 insertions(+), 8 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/sidebar/assets/colors.cljs b/frontend/src/app/main/ui/workspace/sidebar/assets/colors.cljs index e1e70bb2e4..13bd34342c 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/assets/colors.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/assets/colors.cljs @@ -45,6 +45,7 @@ (:value color) (dissoc :value))) color-id (:id color) + menu-id (dm/str "color-options-" file-id "-" color-id) item-ref (mf/use-ref) dragging* (mf/use-state false) @@ -57,6 +58,8 @@ editing? (deref editing*) menu-state (mf/use-state cmm/initial-context-menu-state) + menu-open? (:open? @menu-state) + read-only? (mf/use-ctx ctx/workspace-read-only?) opacity (:opacity color) @@ -143,22 +146,40 @@ :data color :position :right}))) + open-menu + (mf/use-fn + (mf/deps color-id selected on-clear-selection is-local read-only?) + (fn [pos] + (when (and is-local (not read-only?)) + (when-not (contains? selected color-id) + (on-clear-selection)) + (swap! menu-state cmm/open-context-menu pos)))) + on-context-menu (mf/use-fn - (mf/deps color-id selected on-clear-selection read-only?) + (mf/deps open-menu) (fn [event] (dom/prevent-default event) - (let [pos (dom/get-client-position event)] - (when (and is-local (not read-only?)) - (when-not (contains? selected color-id) - (on-clear-selection)) - (swap! menu-state cmm/open-context-menu pos))))) + (open-menu (dom/get-client-position event)))) on-close-menu (mf/use-fn (fn [] (swap! menu-state cmm/close-context-menu))) + on-menu-button-click + (mf/use-fn + (mf/deps open-menu on-close-menu menu-open?) + (fn [event] + ;; Opens the same menu as a right click, for devices without one + ;; (tablets), and closes it on a second click. Stop the click so it + ;; doesn't also apply the color. + (dom/stop-propagation event) + (if menu-open? + (on-close-menu) + (let [rect (dom/get-bounding-rect (dom/get-current-target event))] + (open-menu {:x (:left rect) :y (:bottom rect)}))))) + on-drop (mf/use-fn (mf/deps color dragging* selected selected-full selected-paths move-color) @@ -246,10 +267,21 @@ (:name color) [:span {:class (stl/css :default-name :default-name-with-color)} display-name]])]) + (when (and is-local (not read-only?) (not editing?)) + [:div {:class (stl/css :element-set-actions)} + [:> icon-button* {:variant "action" + :id menu-id + :aria-label (tr "labels.options") + :aria-haspopup "menu" + :aria-expanded menu-open? + :on-click on-menu-button-click + :icon i/menu}]]) + (when is-local [:> cmm/assets-context-menu* {:on-close on-close-menu :state @menu-state + :origin menu-id :options [(when-not (or is-multi-colors is-multi-assets) {:name (tr "workspace.assets.rename") :id "assets-rename-color" diff --git a/frontend/src/app/main/ui/workspace/sidebar/assets/colors.scss b/frontend/src/app/main/ui/workspace/sidebar/assets/colors.scss index 60dfffa9f2..a9de6f89ca 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/assets/colors.scss +++ b/frontend/src/app/main/ui/workspace/sidebar/assets/colors.scss @@ -23,6 +23,7 @@ $assets-button-width: deprecated.$s-28; position: relative; display: grid; grid-template-columns: auto 1fr #{$assets-button-width}; + align-content: center; align-items: center; height: deprecated.$s-32; padding: deprecated.$s-8; @@ -50,8 +51,26 @@ $assets-button-width: deprecated.$s-28; } } - &:hover { + &:hover, + &:focus-within { background-color: var(--assets-item-background-color-hover); + + .element-set-actions { + --actions-opacity: 1; + } + } +} + +.element-set-actions { + display: flex; + + // Hidden with opacity, not visibility, so the button stays in the tab order + // and keyboard focus can reveal it through :focus-within + opacity: var(--actions-opacity, 0); + + // Touch devices have no hover, so keep the options button visible there + @media (hover: none) { + --actions-opacity: 1; } } diff --git a/frontend/src/app/main/ui/workspace/sidebar/assets/common.cljs b/frontend/src/app/main/ui/workspace/sidebar/assets/common.cljs index ba3ff9786e..05ee11baff 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/assets/common.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/assets/common.cljs @@ -114,11 +114,12 @@ (assoc state :open? false)) (mf/defc assets-context-menu* - [{:keys [options state on-close]}] + [{:keys [options state on-close origin]}] [:> context-menu* {:show (:open? state) :fixed (or (not= (:top state) 0) (not= (:left state) 0)) :on-close on-close + :origin origin :top (:top state) :left (:left state) :options options}])