|
@@ -211,22 +211,33 @@
|
|
|
close(false);
|
|
close(false);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- // Escape closes and returns focus; Tab out of the input + popover
|
|
|
|
|
- // closes without focus return.
|
|
|
|
|
|
|
+ // Blur close. Fires when focus leaves either the bound input or a
|
|
|
|
|
+ // focusable element inside the popover (e.g. the slider thumb).
|
|
|
|
|
+ // If focus is moving into the popover itself, or onto another
|
|
|
|
|
+ // eligible input (which the click/focusin handlers will rebind us
|
|
|
|
|
+ // to), we stay open. Any other destination — another cell, the
|
|
|
|
|
+ // page body, a different page element — closes us. This plugs
|
|
|
|
|
+ // the gap where a click elsewhere on the page blurred the input
|
|
|
|
|
+ // but never landed on a registered "outside" target.
|
|
|
|
|
+ function isOurs(el) {
|
|
|
|
|
+ return !!el && (el === boundInput || (pop && pop.contains && pop.contains(el)));
|
|
|
|
|
+ }
|
|
|
|
|
+ document.addEventListener('focusout', function (ev) {
|
|
|
|
|
+ if (!pop || pop.hidden) { return; }
|
|
|
|
|
+ if (!isOurs(ev.target)) { return; }
|
|
|
|
|
+ const next = ev.relatedTarget;
|
|
|
|
|
+ if (isOurs(next)) { return; } // staying inside our realm
|
|
|
|
|
+ if (isEligible(next)) { return; } // another number input — will rebind
|
|
|
|
|
+ close(false);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // Escape closes and returns focus. Tab is now handled via the
|
|
|
|
|
+ // generic focusout listener above.
|
|
|
document.addEventListener('keydown', function (ev) {
|
|
document.addEventListener('keydown', function (ev) {
|
|
|
if (!pop || pop.hidden) { return; }
|
|
if (!pop || pop.hidden) { return; }
|
|
|
if (ev.key === 'Escape') {
|
|
if (ev.key === 'Escape') {
|
|
|
ev.preventDefault();
|
|
ev.preventDefault();
|
|
|
close(true);
|
|
close(true);
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- if (ev.key === 'Tab') {
|
|
|
|
|
- setTimeout(function () {
|
|
|
|
|
- const active = document.activeElement;
|
|
|
|
|
- if (active === boundInput) { return; }
|
|
|
|
|
- if (pop.contains(active)) { return; }
|
|
|
|
|
- close(false);
|
|
|
|
|
- }, 0);
|
|
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|