Skip to content

Commit

Permalink
Trap focus in topmost modal on screen readers
Browse files Browse the repository at this point in the history
Close #7998

Co-authored-by: ivk <ivk@tutao.de>
  • Loading branch information
hrb-hub and charlag committed Dec 17, 2024
1 parent cabc224 commit f77662e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 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(overlay), m(modal), vnode.children],
[m(overlay), m(modal), m(".main-view", { inert: modal.visible }, vnode.children)],
)
}

Expand Down
11 changes: 4 additions & 7 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, remove } from "@tutao/tutanota-utils"
import { insideRect, lastIndex, remove } from "@tutao/tutanota-utils"
import { LayerType } from "../../../RootView"
import { assertMainOrNodeBoot } from "../../api/common/Env"

Expand Down Expand Up @@ -36,12 +36,8 @@ class Modal implements Component {
return m(
"#modal.fill-absolute",
{
oncreate: (_) => {
// const lastComponent = last(this.components)
// if (lastComponent) {
// lastComponent.component.backgroundClick(e)
// }
},
"aria-modal": true,
inert: !this.visible,
style: {
"z-index": LayerType.Modal,
display: this.visible ? "" : "none",
Expand All @@ -52,6 +48,7 @@ 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 Down

0 comments on commit f77662e

Please sign in to comment.