Skip to content

Commit

Permalink
Refactor handling of focusTrap.onDeactivate method
Browse files Browse the repository at this point in the history
Turns out `focus-trap` was not the culprit here, but the fact that we resolved the modal _after_ calling the `deactivate` method on the focus trap.

The changes to the events in the dependency were purely coincidental, but using the newly introduced events happended to fix the issue as well as the `onPostDeactivate` happens to run a tick later than the `onDeactivate` which is enough for the `resolve` to happen.

Re #565
  • Loading branch information
pichfl committed Apr 12, 2022
1 parent 19f6617 commit e7bc5b7
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions addon/components/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export default Component.extend({
let options = {
...this.focusTrapOptions,
fallbackFocus: `#${this.modalElementId}`,
onPostDeactivate: (...args) => {
this.focusTrapOptions.onPostDeactivate?.(...args);
onDeactivate: (...args) => {
this.focusTrapOptions.onDeactivate?.(...args);

if (this.isDestroyed || this.isDestroying) {
return;
Expand Down Expand Up @@ -99,18 +99,18 @@ export default Component.extend({
// Trigger out animation
set(this, 'animatingOutClass', this.outAnimationClass);

if (this.focusTrap) {
this.focusTrap.deactivate({
onDeactivate: this.focusTrapOptions.onDeactivate,
});
}

this.modal._resolve(result);
},

actions: {
close(result) {
this.closeModal(result);

if (this.focusTrap) {
this.focusTrap.deactivate({
onDeactivate: this.focusTrapOptions.onDeactivate,
});
}
},
},
});

0 comments on commit e7bc5b7

Please sign in to comment.