diff --git a/src/theme/book.js b/src/theme/book.js index c2deb79c..df2c1251 100644 --- a/src/theme/book.js +++ b/src/theme/book.js @@ -372,7 +372,15 @@ function playpen_text(playpen) { }); themePopup.addEventListener('focusout', function(e) { - if (!themePopup.contains(e.relatedTarget)) { + // e.relatedTarget is null in Safari and Firefox on macOS (see workaround below) + if (!!e.relatedTarget && !themePopup.contains(e.relatedTarget)) { + hideThemes(); + } + }); + + // Should not be needed, but it works around an issue on macOS & iOS: https://github.com/rust-lang-nursery/mdBook/issues/628 + document.addEventListener('click', function(e) { + if (themePopup.style.display === 'block' && !themeToggleButton.contains(e.target) && !themePopup.contains(e.target)) { hideThemes(); } });