MCPcopy Index your code
hub / github.com/reactstrap/reactstrap / trapFocus

Function trapFocus

src/Offcanvas.js:268–301  ·  view source on GitHub ↗
(ev)

Source from the content-addressed store, hash-verified

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 {

Callers

nothing calls this directly

Calls 1

focusMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…