(ev)
| 319 | } |
| 320 | |
| 321 | trapFocus(ev) { |
| 322 | if (!this.props.trapFocus) { |
| 323 | return; |
| 324 | } |
| 325 | |
| 326 | if (!this._element) { |
| 327 | // element is not attached |
| 328 | return; |
| 329 | } |
| 330 | |
| 331 | if (this._dialog && this._dialog.parentNode === ev.target) { |
| 332 | // initial focus when the Modal is opened |
| 333 | return; |
| 334 | } |
| 335 | |
| 336 | if (this.modalIndex < Modal.openCount - 1) { |
| 337 | // last opened modal |
| 338 | return; |
| 339 | } |
| 340 | |
| 341 | const children = this.getFocusableChildren(); |
| 342 | |
| 343 | for (let i = 0; i < children.length; i += 1) { |
| 344 | // focus is already inside the Modal |
| 345 | if (children[i] === ev.target) return; |
| 346 | } |
| 347 | |
| 348 | if (children.length > 0) { |
| 349 | // otherwise focus the first focusable element in the Modal |
| 350 | ev.preventDefault(); |
| 351 | ev.stopPropagation(); |
| 352 | children[0].focus(); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | init() { |
| 357 | try { |
nothing calls this directly
no test coverage detected
searching dependent graphs…