Browse Source

Improve focus handling

pull/286/head
Jānis Skarnelis 3 years ago
parent
commit
e3885ac1eb
  1. 24
      src/Fancybox/Fancybox.js

24
src/Fancybox/Fancybox.js

@ -166,7 +166,8 @@ class Fancybox extends Base {
*/ */
option(name, ...rest) { option(name, ...rest) {
const slide = this.getSlide(); const slide = this.getSlide();
const value = slide ? slide[name] : undefined;
let value = slide ? slide[name] : undefined;
if (value !== undefined) { if (value !== undefined) {
if (typeof value === "function") { if (typeof value === "function") {
@ -558,14 +559,12 @@ class Fancybox extends Base {
return; return;
} }
// Skip if clicked inside content area if (!eventTarget.matches(FOCUSABLE_ELEMENTS)) {
const content_class = ".fancybox__content";
if (eventTarget.closest(content_class)) {
if (eventTarget.matches(content_class)) {
document.activeElement.blur(); document.activeElement.blur();
} }
// Skip if clicked inside content area
if (eventTarget.closest(".fancybox__content")) {
return; return;
} }
@ -718,16 +717,21 @@ class Fancybox extends Base {
return; return;
} }
const $container = this.$container;
const currentSlide = this.getSlide();
const $currentSlide = currentSlide.state === "done" ? currentSlide.$el : null;
// Skip if the DOM element that is currently in focus is already inside the current slide
if ($currentSlide && $currentSlide.contains(document.activeElement)) {
return;
}
if (event) { if (event) {
event.preventDefault(); event.preventDefault();
} }
Fancybox.ignoreFocusChange = true; Fancybox.ignoreFocusChange = true;
const $container = this.$container;
const currentSlide = this.getSlide();
const $currentSlide = currentSlide.state === "done" ? currentSlide.$el : null;
const allFocusableElems = Array.from($container.querySelectorAll(FOCUSABLE_ELEMENTS)); const allFocusableElems = Array.from($container.querySelectorAll(FOCUSABLE_ELEMENTS));
let enabledElems = []; let enabledElems = [];

Loading…
Cancel
Save