Skip to content

Commit 82163c4

Browse files
josephperrottjelbourn
authored andcommitted
chore(select): use computed pseudocheckbox size for multi select during 2018 material spec update transition (#13110)
1 parent 2f2e116 commit 82163c4

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/lib/select/select.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,17 @@ export const SELECT_PANEL_INDENT_PADDING_X = SELECT_PANEL_PADDING_X * 2;
117117
/** The height of the select items in `em` units. */
118118
export const SELECT_ITEM_HEIGHT_EM = 3;
119119

120+
// TODO(josephperrott): Revert to a constant after 2018 spec updates are fully merged.
120121
/**
121122
* Distance between the panel edge and the option text in
122123
* multi-selection mode.
123124
*
125+
* Calculated as:
124126
* (SELECT_PANEL_PADDING_X * 1.5) + 20 = 44
125127
* The padding is multiplied by 1.5 because the checkbox's margin is half the padding.
126128
* The checkbox width is 20px.
127129
*/
128-
export const SELECT_MULTIPLE_PANEL_PADDING_X = SELECT_PANEL_PADDING_X * 1.5 + 20;
130+
export let SELECT_MULTIPLE_PANEL_PADDING_X = 0;
129131

130132
/**
131133
* The select panel will only "fit" inside the viewport if it is positioned at
@@ -764,6 +766,7 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
764766
*/
765767
_onAttached(): void {
766768
this.overlayDir.positionChange.pipe(take(1)).subscribe(() => {
769+
this._setPseudoCheckboxPaddingSize();
767770
this._changeDetectorRef.detectChanges();
768771
this._calculateOverlayOffsetX();
769772
this.panel.nativeElement.scrollTop = this._scrollTop;
@@ -775,6 +778,17 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
775778
return this._parentFormField ? `mat-${this._parentFormField.color}` : '';
776779
}
777780

781+
// TODO(josephperrott): Remove after 2018 spec updates are fully merged.
782+
/** Sets the pseudo checkbox padding size based on the width of the pseudo checkbox. */
783+
private _setPseudoCheckboxPaddingSize() {
784+
if (!SELECT_MULTIPLE_PANEL_PADDING_X && this.multiple) {
785+
const pseudoCheckbox = this.panel.nativeElement.querySelector('.mat-pseudo-checkbox');
786+
if (pseudoCheckbox) {
787+
SELECT_MULTIPLE_PANEL_PADDING_X = SELECT_PANEL_PADDING_X * 1.5 + pseudoCheckbox.offsetWidth;
788+
}
789+
}
790+
}
791+
778792
/** Whether the select has a value. */
779793
get empty(): boolean {
780794
return !this._selectionModel || this._selectionModel.isEmpty();

0 commit comments

Comments
 (0)