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










share|improve this question




















  • 1




    According to this: github.com/angular/material2/issues/10684 you can't.
    – Jacopo Sciampi
    Nov 8 at 10:11















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










share|improve this question




















  • 1




    According to this: github.com/angular/material2/issues/10684 you can't.
    – Jacopo Sciampi
    Nov 8 at 10:11













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










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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














  • 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












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.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    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
































    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.






    share|improve this answer



























      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.






      share|improve this answer

























        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.






        share|improve this answer














        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.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 8 at 13:40

























        answered Nov 8 at 13:30









        Marshal

        857313




        857313






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            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




















































































            Popular posts from this blog

            Schultheiß

            Verwaltungsgliederung Dänemarks

            Liste der Kulturdenkmale in Wilsdruff