NgbModalWindow always focus the first element that can be focus.
See original GitHub issueat viewInit of NgbModalWindow it will focus the first element if the page do not have auto focus, it will cause the close button often get focus when page no auto focus. whether provide a way to control this behavior?
if (!nativeElement.contains(document.activeElement)) { const autoFocusable = nativeElement.querySelector(
[ngbAutofocus]`) as HTMLElement;
const firstFocusable = getFocusableBoundaryElements(nativeElement)[0];
const elementToFocus = autoFocusable || firstFocusable || nativeElement;
elementToFocus.focus();
}`
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Angular7 and NgbModal: how to remove default auto focus
By default the focus is on the first focusable element within modal, which in your case is the close button. You can add...
Read more >Modal - Angular powered Bootstrap
You can pass an existing component as content of the modal window. ... First focusable element within the modal window will receive focus...
Read more >Dialog / How To / Prevent the focus on the first element
By default, the dialog focuses on the first elements of the content area which can be active and focusable. You can prevent this...
Read more >Using JavaScript to trap focus in an element | hidde.blog
When a user presses TAB , the next focusable element receives focus. If this element is outside our component, focus should be set...
Read more >How to Set Focus on Input Field or Textarea Inside a Bootstrap ...
You can simply use the jQuery .focus() method to set the focus on the first input box or textarea inside the Bootstrap modal...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You can simply add the ngbAutofocus attribute on a non-focusable element of the template. Here’s a demo: https://stackblitz.com/edit/angular-8mhynd?file=src/app/modal-basic.html
Hi, I find this to be a little bit tricky, so maybe we should add such use case to the docs. Thank you! 🙏