Improve modal focus handling with NgbAutoFocus directive and first element focus
See original GitHub issue- Allow users to set the initial focus inside the modal with
NgbAutoFocus
directive.
<!-- will be focused after the modal opens -->
<input type="text" ngbAutoFocus />
- If there is no
ngbAutoFocus
in the modal, focus first focusable element by default. Allow user to cancel this behaviour and focus nothing by doing
modal.open(content, {focusFirst: false})
- add a demo for focus handling in a separate PR
Not sure if this is a breaking change and not sure if we need ngbAutoFocus
as a directive or a simple attribute would do.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:6 (4 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 >Adding autofocus to an input field in an Angular 5 Bootstrap 4 ...
The issue was that input field was auto focussed only the first time I ... start typing without having to manually focus the...
Read more >Modal - Angular powered Bootstrap
First focusable element within the modal window will receive focus upon opening. ... to focus any other element by adding an ngbAutofocus attribute...
Read more >How to set focus on input in modal? - MDBootstrap
If I use <input autofocus> or attempt to set focus dynamically on an input inside modal body, it would not work. How do...
Read more >Angular7 And Ngbmodal: How To Remove Default Auto Focus
If there is no ngbAutoFocus in the modal, focus first focusable If there is ... for run focus trap event handlers outside Angular...
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 FreeTop 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
Top GitHub Comments
@maxokorokov : modal.open(content, {focusFirst: false}) is this feature removed from V4, because i am not able to see
focusFirst
property in NgbModalOptions. if yes how to achieve a situation where i don’t want to set any default focus but should be able to close the modal withESC
key.hi folks, just wondering why the custom (and new) directive instead of using native
autofocus
? (I know that part, it does not work in first place, dynamic content behaviour, etc). But in the guts of the pending PR plain selector is being using:https://github.com/ng-bootstrap/ng-bootstrap/pull/2737/files#diff-8fb1cd1cc4cf9a5207c30f1474b6c8b9R67
and I think this does not differ much from:
Thanks!