Skip to content

fix(select): panel content blurry in some browsers #11434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/lib/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2833,7 +2833,9 @@ describe('MatSelect', () => {
const rawYOrigin = selectInstance._transformOrigin.split(' ')[1].trim();
const origin = Math.floor(parseInt(rawYOrigin));

expect(origin).toBe(expectedOrigin,
// Because the origin depends on the Y axis offset, we also have to
// round down and check that the difference is within a pixel.
expect(Math.abs(expectedOrigin - origin) < 2).toBe(true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use Math.floor or Math.ceil to avoid this absolute check?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine; using abs is the canonical way of checking the magnitude of a delta when you don't care about which is larger

`Expected panel animation to originate in the center of option ${index}.`);
}

Expand Down
13 changes: 7 additions & 6 deletions src/lib/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1085,8 +1085,9 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
}

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

Expand Down Expand Up @@ -1130,10 +1131,10 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
optionOffsetFromPanelTop = scrollBuffer - itemHeight / 2;
}

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

/**
Expand Down