Skip to content

Commit

Permalink
fix: mixin events
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardocavazza committed Jun 27, 2021
1 parent fd59499 commit f875e83
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/Manager.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { window } from '@chialab/dna';
import { Context } from './Context.js';
import { ESC_KEY, TAB_KEY } from './keys.js';

Expand Down
34 changes: 16 additions & 18 deletions src/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,28 @@ import { windowManager } from './Manager.js';

/**
* Enable focus trap context for components.
* @param {import('@chialab/dna').ComponentConstructor<HTMLElement>} superClass The base component class.
* @template {import('@chialab/dna').ComponentConstructor<HTMLElement>} T
* @param {T} superClass The base component class.
* @param {import('./Context.js').ContextOptions} [options] Focus trap options.
* @return An extended constructor.
*/
export const focusTrapMixin = (superClass, options) => class FocusTrapElement extends superClass {
static get listeners() {
return {
'focusenter'() {
this.onFocusEnter();
},
'focusexit'() {
this.onFocusExit();
},
};
}

/**
* The keyboard navigation context.
* @readonly
* @inheritdoc
*/
context = new Context(this, {
dismiss: this.onFocusDismiss.bind(this),
...options,
});
constructor(...args) {
super(...args);
/**
* The keyboard navigation context.
* @readonly
*/
this.context = new Context(this, {
dismiss: this.onFocusDismiss.bind(this),
...options,
});
this.addEventListener('focusenter', this.onFocusEnter);
this.addEventListener('focusexit', this.onFocusExit);
}

/**
* @inheritdoc
Expand Down

0 comments on commit f875e83

Please sign in to comment.