Skip to content

Commit

Permalink
fix(ui): disable the global keyboard shortcuts when another modal is …
Browse files Browse the repository at this point in the history
…shown
  • Loading branch information
updraft0 committed Jun 21, 2024
1 parent 0d395d5 commit 6e703f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ui/src/main/scala/controltower/component/Modal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import org.scalajs.dom.MouseEvent
given equalEventTarget[El <: dom.Element]: CanEqual[dom.EventTarget, El] = CanEqual.derived

object Modal:
val Shown: Var[Boolean] = Var(false)
lazy val onClose: EventProp[dom.UIEvent] = eventProp("close")

// def create(mods: Mod[ReactiveHtmlElement[dom.HTMLDialogElement]]*): Modal = new Modal(mods*)
Expand All @@ -60,6 +61,7 @@ object Modal:
val detached = renderDetached(dialog, activateNow = true)
dialog.amend(
onClose --> { _ =>
Shown.set(false)
onCloseObs.onNext(())
owner.killSubscriptions()
detached.deactivate()
Expand All @@ -69,6 +71,7 @@ object Modal:
dialog.ref.close()
}
)
Shown.set(true)
dialog.ref.showModal()

def showConfirmation(
Expand Down
4 changes: 3 additions & 1 deletion ui/src/main/scala/controltower/page/map/view/MapView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,9 @@ private final class MapView(
documentEvents(
_.onKeyDown
.filter(ev => !ev.repeat && ev.code == code && !ev.ctrlKey && !ev.shiftKey && !ev.metaKey)
).compose(es => compose(es).filterWith(shouldEnable).filterWith(notInKeyHandler.signal)) --> { (ev, b) =>
).compose(es =>
compose(es).filterWith(Modal.Shown.signal.map(!_)).filterWith(shouldEnable).filterWith(notInKeyHandler.signal)
) --> { (ev, b) =>
ev.preventDefault()
inKeyHandler.set(true)
action(b, Observer(_ => inKeyHandler.set(false)))
Expand Down

0 comments on commit 6e703f2

Please sign in to comment.