3

我正在尝试更改 mdc-select 中下拉箭头的默认紫色:

带有紫色下拉箭头的 mdc-select

没有一个 sass mixin 似乎可以做到这一点。

它是如何完成的?

这是我到目前为止所尝试的:

HTML

<div class="mdc-select mdc-select--outlined">
    <input type="hidden" name="enhanced-select">
    <i class="mdc-select__dropdown-icon"></i>
    <div class="mdc-select__selected-text" class="mdc-select__selected-text" role="button" aria-haspopup="listbox" aria-labelledby="demo-label"></div>
    <div class="mdc-select__menu mdc-menu mdc-menu-surface">
        <ul class="mdc-list">
            <li class="mdc-list-item" data-value="41" role="option">41</li>
            <li class="mdc-list-item" data-value="42" role="option">42</li>
            <li class="mdc-list-item" data-value="43" role="option">43</li>
        </ul>
    </div>
    <div class="mdc-notched-outline">
        <div class="mdc-notched-outline__leading"></div>
        <div class="mdc-notched-outline__notch">
            <label class="mdc-floating-label">Answer to Life</label>
        </div>
        <div class="mdc-notched-outline__trailing"></div>
    </div>
</div>  

SCSS

@import "@material/list/mdc-list";
@import "@material/menu-surface/mdc-menu-surface";
@import "@material/menu/mdc-menu";
@import "@material/select/mdc-select";

.mdc-select {
    @include mdc-select-ink-color(red);
    // @include mdc-select-container-fill-color(red);
    @include mdc-select-label-color(red);
    @include mdc-select-focused-label-color(red);
    @include mdc-select-bottom-line-color(red);
    @include mdc-select-focused-bottom-line-color(red);
    @include mdc-select-hover-bottom-line-color(red);
    @include mdc-select-outline-color(red);
    @include mdc-select-focused-outline-color(red);
    @include mdc-select-hover-outline-color(red);
    @include mdc-select-icon-color(red);
}

TS

import { MDCSelect } from '@material/select';
const select = new MDCSelect(document.querySelector('.mdc-select'));
4

3 回答 3

5

这不是一个图标或字体这个箭头是类的背景图像.mdc-select--focused .mdc-select__dropdown-icon。您可以使用filtercss 属性更改图像颜色。

filter: hue-rotate(60deg);

将此 css 应用到您的自定义 css 以.mdc-select--focused .mdc-select__dropdown-icon使其工作。

谢谢你。

于 2019-09-10T12:34:55.517 回答
1

我设法通过使用 MDC 内部 Sass mixin 来对其进行主题化:mdc-select-dd-arrow-svg-bg_. 一个例子是:

.mdc-select .mdc-select__dropdown-icon {
    @include mdc-select-dd-arrow-svg-bg_(COLOR, 1);
}

其中COLOR是 MDC 主题属性(例如'secondary')或 HTML 颜色(例如#ff0000)。它不能是 var,因为正如@KuldipKoradia 所指出的,SVG 是在编译时生成的。

于 2019-11-08T13:18:50.157 回答
0

最简单最简单的方法是隐藏 SVG 并通过 CSS 创建自己的下拉箭头(无需更改 HTML)。然后,您可以根据需要轻松更改颜色:

.mdc-select__dropdown-icon{
  background: none;
  width: 0;
  height: 0;
  bottom: 24px;
  right: 10px;  
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid #333333;
}
.mdc-select--activated .mdc-select__dropdown-icon,
.mdc-select--focused .mdc-select__dropdown-icon {
  border-top: 5px solid #FF0000;
}
于 2020-01-03T23:48:46.280 回答