Skip to content

Commit

Permalink
fix(tooltip): fix instantiation upon focus (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
asudoh authored and marijohannessen committed Jun 20, 2017
1 parent a5374b2 commit febb5be
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/globals/js/mixins/init-component-by-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,20 @@ export default function (ToMix) {
if (target.nodeType === Node.ELEMENT_NODE && target.matches(effectiveOptions.selectorInit)) {
this.create(target, options);
} else {
const handles = effectiveOptions.initEventNames.map(name => on(target, name, (event) => {
const element = eventMatches(event, effectiveOptions.selectorInit);
if (element && !this.components.has(element)) {
const component = this.create(element, options);
if (typeof component.createdByEvent === 'function') {
component.createdByEvent(event);
// To work around non-bubbling `focus` event, use `focusin` event instead of it's available, and "capture mode" otherwise
const hasFocusin = 'onfocusin' in (target.nodeType === Node.ELEMENT_NODE ? target.ownerDocument : target).defaultView;
const handles = effectiveOptions.initEventNames.map((name) => {
const eventName = name === 'focus' && hasFocusin ? 'focusin' : name;
return on(target, eventName, (event) => {
const element = eventMatches(event, effectiveOptions.selectorInit);
if (element && !this.components.has(element)) {
const component = this.create(element, options);
if (typeof component.createdByEvent === 'function') {
component.createdByEvent(event);
}
}
}
}));
}, name === 'focus' && !hasFocusin);
});
return {
release() {
for (let handle = handles.pop(); handle; handle = handles.pop()) {
Expand Down

0 comments on commit febb5be

Please sign in to comment.