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

support autofoucs attribute #762

Closed
achimha opened this issue Aug 21, 2018 · 4 comments · Fixed by #924
Closed

support autofoucs attribute #762

achimha opened this issue Aug 21, 2018 · 4 comments · Fixed by #924

Comments

@achimha
Copy link

achimha commented Aug 21, 2018

The component should support the HTML5 autofocus attribute and assign it to its input. This removes the need to write code calling the focus method after a timeout.

@jennifer-elyse
Copy link

Since autofocus isn't supported yet, is there a way to set focus?

@achimha
Copy link
Author

achimha commented Sep 10, 2018

@ViewChild('ngSelect') ngSelect: NgSelectComponent;

ngAfterViewInit() {
        if (this.autofocus) {
            setTimeout(() => {
                this.ngSelect.focus();
            });
        }
    }

varnastadeus added a commit that referenced this issue Nov 6, 2018
varnastadeus added a commit that referenced this issue Nov 6, 2018
* feat(autofocus): focus if attribute is present
closes #762
NickMele pushed a commit to NickMele/ng-select that referenced this issue Apr 12, 2019
* feat(autofocus): focus if attribute is present
closes ng-select#762
@RebeccaWeber
Copy link

I would like to set autofocus conditionally. Unfortunately, [attr.autofocus]="shouldFocus" does not seem to work. Is there a way to set it conditionally?

@mnyamor
Copy link

mnyamor commented Nov 19, 2020

Apparently adding autofocus to ng-select kinda works ( I know autofoucs is private ) but it's all depending on how you use it. Tried to add it here

https://stackblitz.com/run?file=src/output-events-example.component.html

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

Successfully merging a pull request may close this issue.

6 participants