Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pressing Enter Key causes duplicate windows #39

Closed
bculley opened this issue Mar 27, 2018 · 6 comments
Closed

Pressing Enter Key causes duplicate windows #39

bculley opened this issue Mar 27, 2018 · 6 comments

Comments

@bculley
Copy link

bculley commented Mar 27, 2018

If I open a modal, then press the enter key on the keyboard, that modal is opened again along with the blocking container, causing it to get darker and open new windows on every press of enter.

@bculley
Copy link
Author

bculley commented Mar 27, 2018

So I noticed this was because the dialog has no focus and the original button in angular still has the focus underneath. The enter key is retriggering the original button. Is there a way to set focus anywhere on the modal automatically?

@kevcjones-archived
Copy link
Collaborator

My initial feeling is that it might be valid for me to force a blur event... but I think 'focus' is something the content implementer would be better in control of. For now, could you do your focusing inside ngAfterViewInit()?

@bculley
Copy link
Author

bculley commented Mar 28, 2018

@kevcjones I actually did it in ngOnInit and it works using the ViewChild. Thanks. Yeah I wasn't sure if it should be part of the repo or on the implementer either. For anyone else interested here is my basic solution to grab focus onto the modal onto one of the buttons

with my button in the modal footer
<button #btnSubmit type="button" id="btnSubmit" (click)="submitClick()">Submit</button>

and the modal component code

    // get submit button from view
    @ViewChild('btnSubmit') input: ElementRef; 

    ngOnInit(): void {
        // set focus to submit button
        this.input.nativeElement.focus();
    }

@kevcjones-archived
Copy link
Collaborator

kevcjones-archived commented Mar 28, 2018 via email

@kevcjones-archived
Copy link
Collaborator

kevcjones-archived commented Mar 28, 2018 via email

@kevcjones-archived
Copy link
Collaborator

Closing this for now - there are ways to achieve without adding the functionality to the core just yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants