Skip to content

Commit

Permalink
Add a fallback for missing uiContextualLayerPositioner (#781)
Browse files Browse the repository at this point in the history
  • Loading branch information
CvX authored and sindresorhus committed Feb 17, 2019
1 parent 4da8f6d commit 1ca841e
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions source/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,20 @@ async function withMenu(
menuButtonElement.click();

// Wait for the menu to close before removing the 'hide-dropdowns' class
const menuLayer = document.querySelector<HTMLElement>(
'.uiContextualLayerPositioner:not(.hidden_elem)'
)!;
const menuLayer = document.querySelector('.uiContextualLayerPositioner:not(.hidden_elem)');

const observer = new MutationObserver(() => {
if (menuLayer.classList.contains('hidden_elem')) {
classList.remove('hide-dropdowns');
observer.disconnect();
}
});
observer.observe(menuLayer, {attributes: true, attributeFilter: ['class']});
if (menuLayer) {
const observer = new MutationObserver(() => {
if (menuLayer.classList.contains('hidden_elem')) {
classList.remove('hide-dropdowns');
observer.disconnect();
}
});
observer.observe(menuLayer, {attributes: true, attributeFilter: ['class']});
} else {
// Fallback in case .uiContextualLayerPositioner is missing
classList.remove('hide-dropdowns');
}

await callback();
}
Expand Down

0 comments on commit 1ca841e

Please sign in to comment.