| 32 | container.setAttribute('aria-modal', 'true'); |
| 33 | container.tabIndex = -1; |
| 34 | const onKeydown = event => { |
| 35 | if (event.defaultPrevented) return; |
| 36 | if (event.key === 'Escape') { |
| 37 | event.preventDefault(); |
| 38 | event.stopPropagation(); |
| 39 | close(); |
| 40 | } else if (event.key === 'Tab') { |
| 41 | const controls = OCA.Analytics.Dialog.focusable(container); |
| 42 | const index = controls.indexOf(document.activeElement); |
| 43 | if (!controls.length || index < 0 || (!event.shiftKey && index === controls.length - 1) |
| 44 | || (event.shiftKey && index === 0)) { |
| 45 | event.preventDefault(); |
| 46 | (event.shiftKey ? controls.at(-1) : controls[0])?.focus(); |
| 47 | } |
| 48 | } |
| 49 | }; |
| 50 | container.addEventListener('keydown', onKeydown); |
| 51 | container._analyticsDialogDeactivate = () => { |
| 52 | container.removeEventListener('keydown', onKeydown); |