✨ Add an options button to color assets (#13189)

* ✨ 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

* 🐛 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

* 🐛 Toggle the color asset menu and fix its row and focus

---------

Co-authored-by: Luis de Dios <luis.dedios@kaleidos.net>
This commit is contained in:
Himanshu Bhardwaj 2026-11-25 00:29:45 +05:30 committed by GitHub
parent 07c3409ad0
commit f3baec6658
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 60 additions and 8 deletions

View File

@ -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"

View File

@ -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;
}
}

View File

@ -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}])