Disable default search on matSelect when keyup
up vote
1
down vote
favorite
With default html select, you can use your keyboard to search an element in this list but the default delay is a bit short. I need to find a solution to make this timer longer.
I am using material with angular 6 and I found no buildin solution (no property or option in doc). I tried to make my own solution but the default event is overriding mine's.
Here is a my implementation with material : https://stackblitz.com/edit/material-tooltip-select-search?file=src%2Fapp%2Fapp.component.html
As you can see, if I tip 't', 'o', 'n' then 'i', Toni is selected for about 0.1s then the browser select the first name starting with 'i' (Iris).
Is there any other solution than implementing my own (or using material search component, that is not the idea) or is there a way to disable default event ?
Thanks in advance !
SOLUTION:
According to Marshal's answer, I made a directive to do the job : https://stackblitz.com/edit/material-select-search?file=src%2Fapp%2Fselect-search.directive.ts
angular angular-material2
add a comment |
up vote
1
down vote
favorite
With default html select, you can use your keyboard to search an element in this list but the default delay is a bit short. I need to find a solution to make this timer longer.
I am using material with angular 6 and I found no buildin solution (no property or option in doc). I tried to make my own solution but the default event is overriding mine's.
Here is a my implementation with material : https://stackblitz.com/edit/material-tooltip-select-search?file=src%2Fapp%2Fapp.component.html
As you can see, if I tip 't', 'o', 'n' then 'i', Toni is selected for about 0.1s then the browser select the first name starting with 'i' (Iris).
Is there any other solution than implementing my own (or using material search component, that is not the idea) or is there a way to disable default event ?
Thanks in advance !
SOLUTION:
According to Marshal's answer, I made a directive to do the job : https://stackblitz.com/edit/material-select-search?file=src%2Fapp%2Fselect-search.directive.ts
angular angular-material2
1
According to this: github.com/angular/material2/issues/10684 you can't.
– Jacopo Sciampi
Nov 8 at 10:11
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
With default html select, you can use your keyboard to search an element in this list but the default delay is a bit short. I need to find a solution to make this timer longer.
I am using material with angular 6 and I found no buildin solution (no property or option in doc). I tried to make my own solution but the default event is overriding mine's.
Here is a my implementation with material : https://stackblitz.com/edit/material-tooltip-select-search?file=src%2Fapp%2Fapp.component.html
As you can see, if I tip 't', 'o', 'n' then 'i', Toni is selected for about 0.1s then the browser select the first name starting with 'i' (Iris).
Is there any other solution than implementing my own (or using material search component, that is not the idea) or is there a way to disable default event ?
Thanks in advance !
SOLUTION:
According to Marshal's answer, I made a directive to do the job : https://stackblitz.com/edit/material-select-search?file=src%2Fapp%2Fselect-search.directive.ts
angular angular-material2
With default html select, you can use your keyboard to search an element in this list but the default delay is a bit short. I need to find a solution to make this timer longer.
I am using material with angular 6 and I found no buildin solution (no property or option in doc). I tried to make my own solution but the default event is overriding mine's.
Here is a my implementation with material : https://stackblitz.com/edit/material-tooltip-select-search?file=src%2Fapp%2Fapp.component.html
As you can see, if I tip 't', 'o', 'n' then 'i', Toni is selected for about 0.1s then the browser select the first name starting with 'i' (Iris).
Is there any other solution than implementing my own (or using material search component, that is not the idea) or is there a way to disable default event ?
Thanks in advance !
SOLUTION:
According to Marshal's answer, I made a directive to do the job : https://stackblitz.com/edit/material-select-search?file=src%2Fapp%2Fselect-search.directive.ts
angular angular-material2
angular angular-material2
edited Nov 9 at 10:32
asked Nov 8 at 9:57
Leix
285
285
1
According to this: github.com/angular/material2/issues/10684 you can't.
– Jacopo Sciampi
Nov 8 at 10:11
add a comment |
1
According to this: github.com/angular/material2/issues/10684 you can't.
– Jacopo Sciampi
Nov 8 at 10:11
1
1
According to this: github.com/angular/material2/issues/10684 you can't.
– Jacopo Sciampi
Nov 8 at 10:11
According to this: github.com/angular/material2/issues/10684 you can't.
– Jacopo Sciampi
Nov 8 at 10:11
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Seems adding this to your component to stop the default propagation on keydown event does the trick.
constructor(){
document.addEventListener('keydown', e => {
if ((e.target as any).nodeName === 'MAT-SELECT') {
e.stopImmediatePropagation();
}
}, true);
}
Please reference this github issue which provides a stackblitz example.
https://github.com/angular/material2/issues/11654
You need to grab the keydown event and stopImmediatePropagation()
before it trickles up to the view/mat-select.. this is why <mat-select placeholder="Favorite food" (keydown)=""
will not solve this because the event has already been processed by the mat-select component by the time (keydown) output is fired via template.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Seems adding this to your component to stop the default propagation on keydown event does the trick.
constructor(){
document.addEventListener('keydown', e => {
if ((e.target as any).nodeName === 'MAT-SELECT') {
e.stopImmediatePropagation();
}
}, true);
}
Please reference this github issue which provides a stackblitz example.
https://github.com/angular/material2/issues/11654
You need to grab the keydown event and stopImmediatePropagation()
before it trickles up to the view/mat-select.. this is why <mat-select placeholder="Favorite food" (keydown)=""
will not solve this because the event has already been processed by the mat-select component by the time (keydown) output is fired via template.
add a comment |
up vote
1
down vote
accepted
Seems adding this to your component to stop the default propagation on keydown event does the trick.
constructor(){
document.addEventListener('keydown', e => {
if ((e.target as any).nodeName === 'MAT-SELECT') {
e.stopImmediatePropagation();
}
}, true);
}
Please reference this github issue which provides a stackblitz example.
https://github.com/angular/material2/issues/11654
You need to grab the keydown event and stopImmediatePropagation()
before it trickles up to the view/mat-select.. this is why <mat-select placeholder="Favorite food" (keydown)=""
will not solve this because the event has already been processed by the mat-select component by the time (keydown) output is fired via template.
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Seems adding this to your component to stop the default propagation on keydown event does the trick.
constructor(){
document.addEventListener('keydown', e => {
if ((e.target as any).nodeName === 'MAT-SELECT') {
e.stopImmediatePropagation();
}
}, true);
}
Please reference this github issue which provides a stackblitz example.
https://github.com/angular/material2/issues/11654
You need to grab the keydown event and stopImmediatePropagation()
before it trickles up to the view/mat-select.. this is why <mat-select placeholder="Favorite food" (keydown)=""
will not solve this because the event has already been processed by the mat-select component by the time (keydown) output is fired via template.
Seems adding this to your component to stop the default propagation on keydown event does the trick.
constructor(){
document.addEventListener('keydown', e => {
if ((e.target as any).nodeName === 'MAT-SELECT') {
e.stopImmediatePropagation();
}
}, true);
}
Please reference this github issue which provides a stackblitz example.
https://github.com/angular/material2/issues/11654
You need to grab the keydown event and stopImmediatePropagation()
before it trickles up to the view/mat-select.. this is why <mat-select placeholder="Favorite food" (keydown)=""
will not solve this because the event has already been processed by the mat-select component by the time (keydown) output is fired via template.
edited Nov 8 at 13:40
answered Nov 8 at 13:30
Marshal
857313
857313
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205306%2fdisable-default-search-on-matselect-when-keyup%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
According to this: github.com/angular/material2/issues/10684 you can't.
– Jacopo Sciampi
Nov 8 at 10:11