Creating custom arrow in Angular Material sort header

两盒软妹~` 提交于 2020-01-16 19:50:10

问题


I am creating Angular 5 project and I wanted to create custom sort icon in sort header to achieve this effect https://fontawesome.com/icons/caret-up?style=solid. I don't want to have this default arrow.

I tried to change css style, but it seems not to work. Or maybe is there any way to replace this icon by custom using JS?

::ng-deep  {

    .cdk-visually-hidden {
        border: 0;
        clip: rect(0 0 0 0);
        height: 1px;
        margin: -1px;
        overflow: hidden;
        padding: 0;
        position: absolute;
        width: 1px;
    }

    .mat-sort-header-stem {
        background: none;
        display: none !important;
    }

    .mat-sort-header-container {
        position: relative;
    }
    .mat-sort-header-indicator {

      transform: translateY(0px) !important;
    }

    .mat-sort-header-arrow {
        position: absolute;
        right: 20px;
        transform: translateY(0%) !important;
    }


  } 

Thank for any suggestions.

Edit.

If someone has this problem, I solved it by adding custom directive to mat-sort-header element. I also passed to directive the sort direction (ASC or DESC). Finally based on the direction I customized my sort icon using pure CSS.


回答1:


see if this help you

.triangle {
    overflow: hidden;
    position: relative;
    margin: 2em auto;
    border-radius: 20%;
    transform: translateY(50%) rotate(30deg) skewY(30deg) scaleX(.866);
    width: 5em;
    height: 5em;
}

.triangle:before {
    border-radius: 20% 20% 20% 53%;
    transform: scaleX(1.155) skewY(-30deg) rotate(-30deg) translateY(-42.3%) skewX(30deg) scaleY(.866) translateX(-24%);
    position: absolute;
    background: #ccc;
    pointer-events: auto;
    content: '';
    width: 5em;
    height: 5em;
}

.triangle:after {
    border-radius: 20% 20% 53% 20%;
    transform: scaleX(1.155) skewY(-30deg) rotate(-30deg) translateY(-42.3%) skewX(-30deg) scaleY(.866) translateX(24%);
    position: absolute;
    background: #ccc;
    pointer-events: auto;
    content: '';
    width: 5em;
    height: 5em;
}
<div class="triangle"></div>


来源:https://stackoverflow.com/questions/53648308/creating-custom-arrow-in-angular-material-sort-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!