dialog.js 612 B

123456789101112131415161718192021
  1. import A11yDialog from 'a11y-dialog';
  2. export const dialog = (
  3. dialogs = document.querySelectorAll('[data-dialog]'),
  4. ) => {
  5. dialogs.forEach((template) => {
  6. const html = document.documentElement;
  7. const templateContent = template.content.firstElementChild.cloneNode(true);
  8. document.body.appendChild(templateContent);
  9. const dialogTemplate = new A11yDialog(templateContent);
  10. // Prevent scrolling when dialog is open
  11. dialogTemplate
  12. .on('show', () => {
  13. html.style.overflowY = 'hidden';
  14. })
  15. .on('hide', () => {
  16. html.style.overflowY = '';
  17. });
  18. });
  19. };