Skip to content

Commit

Permalink
Revert "Fix focus not returned to callingElement on modal close"
Browse files Browse the repository at this point in the history
This reverts commit b2ee43c.

Revert "Trap focus in topmost modal on screen readers"

This reverts commit a8f1ce1.

Revert "Fix overlay should be inert when modal is open"

This reverts commit 73fc544
  • Loading branch information
charlag committed Dec 23, 2024
1 parent 77f480b commit d94873b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/RootView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class RootView implements ClassComponent {
height: "100%",
},
},
[m(".fill-absolute.noprint", { inert: modal.visible }, m(overlay)), m(modal), m(".main-view", { inert: modal.visible }, vnode.children)],
[m(overlay), m(modal), vnode.children],
)
}

Expand Down
32 changes: 16 additions & 16 deletions src/common/gui/base/Modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { theme } from "../theme"
import type { Shortcut } from "../../misc/KeyManager"
import { keyManager } from "../../misc/KeyManager"
import { windowFacade } from "../../misc/WindowFacade"
import { insideRect, lastIndex, remove } from "@tutao/tutanota-utils"
import { insideRect, remove } from "@tutao/tutanota-utils"
import { LayerType } from "../../../RootView"
import { assertMainOrNodeBoot } from "../../api/common/Env"

Expand Down Expand Up @@ -36,8 +36,12 @@ class Modal implements Component {
return m(
"#modal.fill-absolute",
{
"aria-modal": true,
inert: !this.visible,
oncreate: (_) => {
// const lastComponent = last(this.components)
// if (lastComponent) {
// lastComponent.component.backgroundClick(e)
// }
},
style: {
"z-index": LayerType.Modal,
display: this.visible ? "" : "none",
Expand All @@ -48,7 +52,6 @@ class Modal implements Component {
".fill-absolute",
{
key: wrapper.key,
inert: i !== lastIndex(array),
oncreate: (vnode) => {
// do not set visible=true already in display() because it leads to modal staying open in a second window in Chrome
// because onbeforeremove is not called in that case to set visible=false. this is probably an optimization in Chrome to reduce
Expand All @@ -74,11 +77,11 @@ class Modal implements Component {
style: {
zIndex: LayerType.Modal + 1 + i,
},
onbeforeremove: async (vnode) => {
onbeforeremove: (vnode) => {
if (wrapper.needsBg) {
this.closingComponents.push(wrapper.component)

await Promise.all([
return Promise.all([
this.addAnimation(vnode.dom as HTMLElement, false).then(() => {
remove(this.closingComponents, wrapper.component)

Expand All @@ -87,22 +90,16 @@ class Modal implements Component {
}
}),
wrapper.component.hideAnimation(),
])
]).then(() => {
m.redraw()
})
} else {
if (this.components.length === 0 && this.closingComponents.length === 0) {
this.visible = false
}

await wrapper.component.hideAnimation()
return wrapper.component.hideAnimation().then(() => m.redraw())
}

m.redraw()

// Return the focus back to it's calling element.
// We focus callingElement onbeforeremove with requestAnimationFrame because
// focus can't happen if callingElement is inert. And when returning
// focus to main view, focus must happen after redraw that removes inert
requestAnimationFrame(() => wrapper.component.callingElement()?.focus())
},
},
m(wrapper.component),
Expand Down Expand Up @@ -219,6 +216,9 @@ class Modal implements Component {
// the removed component was the last component, so we can now register the shortcuts of the now last component
keyManager.registerModalShortcuts(this.components[this.components.length - 1].component.shortcuts())
}

// Return the focus back to it's calling element.
component.callingElement()?.focus()
}

/**
Expand Down

0 comments on commit d94873b

Please sign in to comment.