question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MDC-Web: Dialog "You can't have a focus-trap without at least one focusable element"

See original GitHub issue

I’m using <script src="//unpkg.com/material-components-web@latest/dist/material-components-web.min.js"></script> w foundation and today am getting an error that I was not getting last week.

material-components-web.min.js:6 Uncaught Error: You can't have a focus-trap without at least one focusable element
    at p (material-components-web.min.js:6)
    at l (material-components-web.min.js:6)
    at Object.n [as activate] (material-components-web.min.js:6)
    at Object.trapFocusOnSurface (material-components-web.min.js:6)
    at e.value (material-components-web.min.js:6)
    at HTMLDivElement.n.transitionEndHandler_ (material-components-web.min.js:6)

Any ideas? I have a <button id="account-cancel" type="button" class="mdc-button mdc-dialog__footer__button mdc-dialog__footer__button--cancel">Cancel</button> in the dialog?..

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

25reactions
johnhaitascommented, Nov 27, 2018

@Download I found a solution to the problem - you must have at least one DrawerItem with the selected attribute

7reactions
abhiomkarcommented, Dec 20, 2018

For future reference I’m linking a complete example of dismissible drawer on stackblitz.

The reason we made it to have at least one focusable element inside drawer because of accessibility reasons.

  • At least one focusable element is required to close the drawer using <kbd>ESC</kbd> key when it is opened and focus is inside drawer.
  • Focus is trapped inside drawer when modal drawer is opened. This requires at least one focusable element to be present.

As suggested above, it is recommended to have at least one drawer item (i.e., mdc-list-item).

@Download Please see this example for use case when none of the drawer items are selected initially. Drawer component itself is not aware which navigation item is currently active, it is also not safe assumption to activate or select first item.

Read more comments on GitHub >

github_iconTop Results From Across the Web

FocusTrap: Element must have at least one focusable child ...
Make sure that your dialog ( .mdc-dialog ) is actually injected in the DOM, and that it contains at least one element a...
Read more >
ERROR Error: You can't have a focus-trap without at least one ...
I got this error in my Angular code for opening a material design dialog(MDCDialog), but I have no clue at the first glance....
Read more >
Showing a dialog with no buttons prints an error in console (You can ...
Showing a dialog with no buttons prints an error in console (You can't have a focus-trap without at least one focusable element)
Read more >
there are no focusable elements inside the <FocusTrap />
This error was being thrown when I tried to use the Simpler Alert Modal of TailwindUI. After googling, the ff resources helped me...
Read more >
How to use the focus-trap function in focus-trap - Snyk
To help you get started, we've selected a few focus-trap examples, ... needs to have at least one focusable element') { console.log('Focus trap...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found