()
| 198 | } |
| 199 | |
| 200 | private async open(): Promise<void> { |
| 201 | if (this.props.onOpen) { |
| 202 | const result = await this.props.onOpen(); |
| 203 | if (Array.isArray(result)) { |
| 204 | this.setItems(result); |
| 205 | } |
| 206 | } |
| 207 | if (!this.menu.parentElement) { |
| 208 | document.body.appendChild(this.menu); |
| 209 | } |
| 210 | if (!this.popper) { |
| 211 | this.popper = createPopper(this.toggle, this.menu, { |
| 212 | placement: this.props.placement === 'bottom' ? 'bottom-start' : 'top-start', |
| 213 | modifiers: [{ name: 'offset', options: { offset: [0, 4] } }] |
| 214 | }); |
| 215 | } else { |
| 216 | this.popper.update(); |
| 217 | } |
| 218 | this.isOpen = true; |
| 219 | this.root.classList.add('open'); |
| 220 | this.menu.classList.add('open'); |
| 221 | this.toggle.setAttribute('aria-expanded', 'true'); |
| 222 | document.addEventListener('mousedown', this.outsideClick, true); |
| 223 | document.addEventListener('keydown', this.onKey, true); |
| 224 | } |
| 225 | |
| 226 | private close(): void { |
| 227 | this.isOpen = false; |
no test coverage detected