0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-10 08:50:57 -05:00

Merge pull request #1933 from penpot/palba-fix-file-menu-not-accessible

🐛 Fix menu file not accessible in certain conditions
This commit is contained in:
Eva Marco 2022-05-24 12:39:42 +02:00 committed by GitHub
commit 3604d0cfc9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 21 deletions

View file

@ -11,6 +11,8 @@
- Multiple team invitations on onboarding [Taiga #3084](https://tree.taiga.io/project/penpot/us/3084)
### :bug: Bugs fixed
- Fix menu file not accessible in certain conditions [Taiga #3385](https://tree.taiga.io/project/penpot/issue/3385)
### :arrow_up: Deps updates
### :heart: Community contributions by (Thank you!)

View file

@ -35,39 +35,45 @@
route (mf/deref refs/route)
in-dashboard? (= :dashboard-projects (:name (:data route)))
local (mf/use-state {:offset 0
local (mf/use-state {:offset-y 0
:offset-x 0
:levels nil})
on-local-close
(mf/use-callback
(fn []
(swap! local assoc :levels [{:parent-option nil
:options options}])
(on-close)))
(fn []
(swap! local assoc :levels [{:parent-option nil
:options options}])
(on-close)))
check-menu-offscreen
(mf/use-callback
(mf/deps top (:offset @local))
(mf/deps top (:offset-y @local) left (:offset-x @local))
(fn [node]
(when (some? node)
(let [{node-height :height} (dom/get-bounding-rect node)
{window-height :height} (dom/get-window-size)
target-offset (if (> (+ top node-height) window-height)
(let [bounding_rect (dom/get-bounding-rect node)
window_size (dom/get-window-size)
{node-height :height node-width :width} bounding_rect
{window-height :height window-width :width} window_size
target-offset-y (if (> (+ top node-height) window-height)
(- node-height)
0)]
0)
target-offset-x (if (> (+ left node-width) window-width)
(- node-width)
0)]
(when (not= target-offset (:offset @local))
(swap! local assoc :offset target-offset))))))
(when (or (not= target-offset-y (:offset-y @local)) (not= target-offset-x (:offset-x @local)))
(swap! local assoc :offset-y target-offset-y :offset-x target-offset-x))))))
enter-submenu
(mf/use-callback
(mf/deps options)
(fn [option-name sub-options]
(fn [event]
(dom/stop-propagation event)
(swap! local update :levels
conj {:parent-option option-name
:options sub-options}))))
(mf/deps options)
(fn [option-name sub-options]
(fn [event]
(dom/stop-propagation event)
(swap! local update :levels
conj {:parent-option option-name
:options sub-options}))))
exit-submenu
(mf/use-callback
@ -87,8 +93,8 @@
[:div.context-menu {:class (dom/classnames :is-open open?
:fixed fixed?
:is-selectable is-selectable)
:style {:top (+ top (:offset @local))
:left left}}
:style {:top (+ top (:offset-y @local))
:left (+ left (:offset-x @local))}}
(let [level (-> @local :levels peek)]
[:ul.context-menu-items {:class (dom/classnames :min-width min-width?)
:ref check-menu-offscreen}