Skip to content

Commit 16c4535

Browse files
authored
refactor: ability to pause modal focus trap (#586)
1 parent f8710b4 commit 16c4535

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,4 @@
126126
"spatie/laravel-permission": "Needed for nova permissions & roles",
127127
"vyuldashev/nova-permission": "Needed for nova permissions & roles"
128128
}
129-
}
129+
}

icons.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

resources/assets/js/modal.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ const Modal = {
8686

8787
this.trappedFocus = trap.activate();
8888
this.trappedElement = el;
89+
90+
window.addEventListener(
91+
"pauseFocusTrap",
92+
this.pauseFocusTrap.bind(this)
93+
);
94+
window.addEventListener(
95+
"resumeFocusTrap",
96+
this.resumeFocusTrap.bind(this)
97+
);
8998
},
9099

91100
releaseTrappedFocus() {
@@ -96,6 +105,31 @@ const Modal = {
96105
this.trappedFocus.deactivate();
97106
this.trappedFocus = null;
98107
this.trappedElement = null;
108+
109+
window.removeEventListener(
110+
"pauseFocusTrap",
111+
this.pauseFocusTrap.bind(this)
112+
);
113+
window.removeEventListener(
114+
"resumeFocusTrap",
115+
this.resumeFocusTrap.bind(this)
116+
);
117+
},
118+
119+
pauseFocusTrap() {
120+
if (!this.trappedFocus) {
121+
return;
122+
}
123+
124+
this.trappedFocus.pause();
125+
},
126+
127+
resumeFocusTrap() {
128+
if (!this.trappedFocus) {
129+
return;
130+
}
131+
132+
this.trappedFocus.unpause();
99133
},
100134

101135
alpine(extraData = {}, modalName = "", eventSettings = {}) {

src/Hermes/Models/DatabaseNotification.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use ARKEcosystem\Foundation\Fortify\Models\Concerns\HasLocalizedTimestamps;
88
use Illuminate\Database\Eloquent\Factories\HasFactory;
9-
use Illuminate\Database\Eloquent\Model;
109
use Illuminate\Database\Eloquent\Relations\MorphTo;
1110
use Illuminate\Notifications\DatabaseNotification as BaseNotification;
1211
use Illuminate\Support\Arr;

0 commit comments

Comments
 (0)