(ev)
| 266 | } |
| 267 | |
| 268 | trapFocus(ev) { |
| 269 | if (!this.props.trapFocus) { |
| 270 | return; |
| 271 | } |
| 272 | |
| 273 | if (!this._element) { |
| 274 | // element is not attached |
| 275 | return; |
| 276 | } |
| 277 | |
| 278 | if (this._dialog.current === ev.target) { |
| 279 | // initial focus when the Offcanvas is opened |
| 280 | return; |
| 281 | } |
| 282 | |
| 283 | if (this.offcanvasIndex < Offcanvas.openCount - 1) { |
| 284 | // last opened offcanvas |
| 285 | return; |
| 286 | } |
| 287 | |
| 288 | const children = this.getFocusableChildren(); |
| 289 | |
| 290 | for (let i = 0; i < children.length; i += 1) { |
| 291 | // focus is already inside the Offcanvas |
| 292 | if (children[i] === ev.target) return; |
| 293 | } |
| 294 | |
| 295 | if (children.length > 0) { |
| 296 | // otherwise focus the first focusable element in the Offcanvas |
| 297 | ev.preventDefault(); |
| 298 | ev.stopPropagation(); |
| 299 | children[0].focus(); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | init() { |
| 304 | try { |
nothing calls this directly
no test coverage detected
searching dependent graphs…