Skip to content

Commit

Permalink
Added passthrough of escapeDeactivates to focus-trap
Browse files Browse the repository at this point in the history
refs mainmatter#435
refs mainmatter#295

https://github.com/focus-trap/focus-trap is used internally for keeping focus inside a modal and for handling modal closing on certain events. If the consuming app wants to manage deactivation/close-inducing events itself then it needs some way to pass `focus-trap` config through to turn off that functionality.

- added `escapeDeactivates` to the options passed through from the `modals` service to the `focus-trap` initialisation
  • Loading branch information
kevinansfield committed Sep 16, 2021
1 parent 5461b70 commit 6ad2f36
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Not recommended for general use, this package will be removed if upstream become

Custom changes:
- added `allowOutsideClick` passthrough from the `modals` service to the `focus-trap` initialisation so `clickOutsideDeactivates` and `allowOutsideClick` and be used in tandem to allow wormholed content such as dropdowns to work inside of a modal
- added `escapeDeactivates` passthrough from the `modals` service to the `focus-trap` initialisation so that deactivation/close event handling can be fully controlled by the consuming app
3 changes: 2 additions & 1 deletion addon/components/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ export default Component.extend({
didInsertElement() {
this._super(...arguments);

let { allowOutsideClick, clickOutsideDeactivates } = this.modals;
let { allowOutsideClick, clickOutsideDeactivates, escapeDeactivates } = this.modals;
let element = document.getElementById(this.modalElementId);
let options = {
allowOutsideClick,
clickOutsideDeactivates,
escapeDeactivates,
fallbackFocus: `#${this.modalElementId}`,
onDeactivate: () => {
if (this.isDestroyed || this.isDestroying) {
Expand Down
3 changes: 2 additions & 1 deletion addon/services/modals.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ export default Service.extend({
}),
top: alias('_stack.lastObject'),

allowOutsideClick: undefined,
allowOutsideClick: false,
clickOutsideDeactivates: true,
escapeDeactivates: true,

init() {
this._super(...arguments);
Expand Down

0 comments on commit 6ad2f36

Please sign in to comment.