Skip to content

Commit 61714ff

Browse files
committed
Make x-trap more friendly with transitions
1 parent 51af642 commit 61714ff

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

packages/focus/src/index.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,15 @@ export default function (Alpine) {
134134

135135
// Start trapping.
136136
if (value && ! oldValue) {
137-
setTimeout(() => {
138-
if (modifiers.includes('inert')) undoInert = setInert(el)
139-
if (modifiers.includes('noscroll')) undoDisableScrolling = disableScrolling()
137+
if (modifiers.includes('noscroll')) undoDisableScrolling = disableScrolling()
138+
if (modifiers.includes('inert')) undoInert = setInert(el)
140139

141-
trap.activate()
142-
});
140+
// Activate the trap after two ticks. (Needed to play nice with transitions...)
141+
setTimeout(() => {
142+
setTimeout(() => {
143+
trap.activate()
144+
})
145+
})
143146
}
144147

145148
// Stop trapping.

0 commit comments

Comments
 (0)