-
-
Notifications
You must be signed in to change notification settings - Fork 133
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
#119 - Issue with scrollTop and keyboard selection #120
#119 - Issue with scrollTop and keyboard selection #120
Conversation
…ing the ngx-mat-select-search input
Any alternative to using _getItemHeight? |
@@ -285,6 +285,30 @@ export class MatSelectSearchComponent implements OnInit, OnDestroy, AfterViewIni | |||
this.changeDetectorRef.markForCheck(); | |||
}); | |||
}); | |||
|
|||
if (this.matSelect._keyManager) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, it looks like at this point, _keyManager was sometimes undefined. (It was the case for the app-custom-clear-icon-example component)
Is there a safer place I could subscribe to the event, where I can know for sure that _keyManager is defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is initialized in the ngAfterContentInit
lifecycle hook:
https://github.com/angular/material2/blob/eb5eed14778f402ea56a096148ff6e78d8bdad93/src/lib/select/select.ts#L542-L543
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should initialize first time after the mat select is opened (See #54):
ngx-mat-select-search/src/app/mat-select-search/mat-select-search.component.ts
Lines 226 to 232 in 4b92230
// set the first item active after the options changed | |
this.matSelect.openedChange | |
.pipe(take(1)) | |
.pipe(takeUntil(this._onDestroy)) | |
.subscribe(() => { | |
this._options = this.matSelect.options; | |
this._options.changes |
however, i would keep the
if (this.matSelect._keyManager) {
and maybe add a console.log() to avoid errors if in some circumstances the keymanager is not initialized yet. See e.g. #53
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the subscribtion and added the console.log.
However, I added a placeholder message for now, let me know what you think it should include.
@Mabiro thanks for your contribution. I will soon have a closer look |
@@ -285,6 +285,30 @@ export class MatSelectSearchComponent implements OnInit, OnDestroy, AfterViewIni | |||
this.changeDetectorRef.markForCheck(); | |||
}); | |||
}); | |||
|
|||
if (this.matSelect._keyManager) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you move your implementation into a separate function? just to make it easier to read...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, sorry about that!
@macjohnny : I am still having the _getItemHeight being a private method issue. I could use |
-Moved the location of keyManager.changes subscription to a later lifecycle
wouldn't it be possible to get the height calculated in the dom with |
I'll give it a shot soon-ish! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
it works well. we should also call adjustScrollTopToFitActiveOptionIntoView()
when the options change to make sure the hightlighted item is visible
thanks a lot for your contribution!
…ge to ensure they are visible
@macjohnny I added adjustScrollTopToFitActiveOptionIntoView on options change :) |
-Attempt at fixing the issue with _scrollActiveOptionIntoView when us…ing the ngx-mat-select-search input
Fixes #119
I still had to import _countGroupLabelsBeforeOption, sadly, to make it work with groups.