|
| 1 | +@import '../../cdk/a11y/a11y'; |
| 2 | + |
| 3 | +// Width of the Material Design form-field select arrow. |
| 4 | +$mat-form-field-select-arrow-width: 10px; |
| 5 | +// Height of the Material Design form-field select arrow. |
| 6 | +$mat-form-field-select-arrow-height: 5px; |
| 7 | +// Horizontal padding that needs to be applied to the native select in an form-field so |
| 8 | +// that the absolute positioned arrow does not overlap the select content. |
| 9 | +$mat-form-field-select-horizontal-end-padding: $mat-form-field-select-arrow-width + 5px; |
| 10 | + |
| 11 | +// Mixin that creates styles for native select controls in a form-field. |
| 12 | +@mixin _mat-form-field-native-select() { |
| 13 | + // Remove the native select down arrow and ensure that the native appearance |
| 14 | + // does not conflict with the form-field. e.g. Focus indication of the native |
| 15 | + // select is undesired since we handle focus as part of the form-field. |
| 16 | + select.mat-mdc-input-element { |
| 17 | + -moz-appearance: none; |
| 18 | + -webkit-appearance: none; |
| 19 | + background-color: transparent; |
| 20 | + display: inline-flex; |
| 21 | + box-sizing: border-box; |
| 22 | + |
| 23 | + // Hides the default arrow native selects. |
| 24 | + &::-ms-expand { |
| 25 | + display: none; |
| 26 | + } |
| 27 | + |
| 28 | + // By default the cursor does not change when hovering over a select. We want to |
| 29 | + // change this for non-disabled select elements so that it's more obvious that the |
| 30 | + // control can be clicked. |
| 31 | + &:not(:disabled) { |
| 32 | + cursor: pointer; |
| 33 | + } |
| 34 | + |
| 35 | + // As a part of its user agent styling, IE11 has a blue box inside each focused `select` |
| 36 | + // element which we have to reset. Note that this needs to be in its own selector, because |
| 37 | + // having it together with another one will cause other browsers to ignore it. |
| 38 | + &::-ms-value { |
| 39 | + // We need to reset the `color` as well, because IE sets it to white. |
| 40 | + color: inherit; |
| 41 | + background: none; |
| 42 | + |
| 43 | + // IE and Edge in high contrast mode reset the color for a focused select to the same color |
| 44 | + // as the background, however this causes it blend in because we've reset the `background` |
| 45 | + // above. We have to add a more specific selector in order to ensure that it gets the |
| 46 | + // `color` from our theme instead. |
| 47 | + @include cdk-high-contrast(active, off) { |
| 48 | + .mat-focused & { |
| 49 | + color: inherit; |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + // Native select elements with the `matInput` directive should have Material Design |
| 56 | + // styling. This means that we add an arrow to the form-field that is based on the |
| 57 | + // Material Design specification. We achieve this by adding a pseudo element to the |
| 58 | + // form-field infix. |
| 59 | + .mat-mdc-form-field-type-mat-native-select { |
| 60 | + .mat-mdc-form-field-infix::after { |
| 61 | + content: ''; |
| 62 | + width: 0; |
| 63 | + height: 0; |
| 64 | + border-left: ($mat-form-field-select-arrow-width / 2) solid transparent; |
| 65 | + border-right: ($mat-form-field-select-arrow-width / 2) solid transparent; |
| 66 | + border-top: $mat-form-field-select-arrow-height solid; |
| 67 | + position: absolute; |
| 68 | + top: 50%; |
| 69 | + right: 0; |
| 70 | + |
| 71 | + // Make the arrow non-clickable so the user can click on the form control under it. |
| 72 | + pointer-events: none; |
| 73 | + |
| 74 | + [dir='rtl'] & { |
| 75 | + right: auto; |
| 76 | + left: 0; |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + // Add padding on the end of the native select so that the content does not |
| 81 | + // overlap with the Material Design arrow. |
| 82 | + .mat-mdc-input-element { |
| 83 | + padding-right: $mat-form-field-select-horizontal-end-padding; |
| 84 | + [dir='rtl'] & { |
| 85 | + padding-right: 0; |
| 86 | + padding-left: $mat-form-field-select-horizontal-end-padding; |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | +} |
0 commit comments