Skip to content

Commit 3dc3fcd

Browse files
crisbetommalerba
authored andcommitted
fix(select): panel content blurry in some browsers (#11434)
After we switched everything over to the `FlexibleConnectedPositionStrategy`, we started using `transform` to handle overlay offsets, however using a subpixel `transform` value will cause some browsers to blur the content of the element. These changes round the select's transforms so the content isn't blurry.
1 parent 7d447c2 commit 3dc3fcd

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/lib/select/select.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2833,7 +2833,9 @@ describe('MatSelect', () => {
28332833
const rawYOrigin = selectInstance._transformOrigin.split(' ')[1].trim();
28342834
const origin = Math.floor(parseInt(rawYOrigin));
28352835

2836-
expect(origin).toBe(expectedOrigin,
2836+
// Because the origin depends on the Y axis offset, we also have to
2837+
// round down and check that the difference is within a pixel.
2838+
expect(Math.abs(expectedOrigin - origin) < 2).toBe(true,
28372839
`Expected panel animation to originate in the center of option ${index}.`);
28382840
}
28392841

src/lib/select/select.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,8 +1085,9 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
10851085
}
10861086

10871087
// Set the offset directly in order to avoid having to go through change detection and
1088-
// potentially triggering "changed after it was checked" errors.
1089-
this.overlayDir.offsetX = offsetX;
1088+
// potentially triggering "changed after it was checked" errors. Round the value to avoid
1089+
// blurry content in some browsers.
1090+
this.overlayDir.offsetX = Math.round(offsetX);
10901091
this.overlayDir.overlayRef.updatePosition();
10911092
}
10921093

@@ -1130,10 +1131,10 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
11301131
optionOffsetFromPanelTop = scrollBuffer - itemHeight / 2;
11311132
}
11321133

1133-
// The final offset is the option's offset from the top, adjusted for the height
1134-
// difference, multiplied by -1 to ensure that the overlay moves in the correct
1135-
// direction up the page.
1136-
return optionOffsetFromPanelTop * -1 - optionHeightAdjustment;
1134+
// The final offset is the option's offset from the top, adjusted for the height difference,
1135+
// multiplied by -1 to ensure that the overlay moves in the correct direction up the page.
1136+
// The value is rounded to prevent some browsers from blurring the content.
1137+
return Math.round(optionOffsetFromPanelTop * -1 - optionHeightAdjustment);
11371138
}
11381139

11391140
/**

0 commit comments

Comments
 (0)