Skip to content
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

Refactor offsetHeight use float-compat API #948

Merged
merged 1 commit into from
Aug 24, 2023

Conversation

mixonic
Copy link
Member

@mixonic mixonic commented May 3, 2022

offsetHeight, per MDN, is an API which returns integer values. This makes is inappropriate to use in calculations of current UI scale (usually from a transform) as it rounds any floating point height into an integer.

This PR changes the getScale function to use getComputedStyle to read off the logical height of the element. This API supports greater precision (to at least 3 digits) though it also may not provide the same level of precision as getBoundingClientRect.

This prevents the positioning data for cells (which is impacted by scale) from being corrupted by heights which are at decimal precision.

@mixonic mixonic force-pushed the mixonic/offsetHeight-is-int branch 2 times, most recently from aceb59c to 5639ca1 Compare May 3, 2022 20:41
@mixonic mixonic force-pushed the mixonic/offsetHeight-is-int branch 2 times, most recently from 79aa4f2 to 77d3950 Compare May 6, 2022 18:25
@@ -29,18 +40,52 @@ const Header = PageObject.extend({

/**
* Retrieves selected header cell width.
*
* Deprecated: offsetWidth returns a rounded integer, and so can
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: use @deprecated jsdoc tag

*/
get width() {
return findElement(this).offsetWidth;
},

/**
* Retrieves selected header cell height.
*
* Deprecated: offsetHeight returns a rounded integer, and so can
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: same

/**
* Resizes this column by dragging right border several pixels.
/*
* This API is deprecated, prefer the more explicit resizeLogicalSize.
Copy link
Contributor

Choose a reason for hiding this comment

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

same

Base automatically changed from 4.0-beta to master May 18, 2022 13:34
@mixonic mixonic force-pushed the mixonic/offsetHeight-is-int branch from 77d3950 to f3eb2b4 Compare May 20, 2022 20:41
@mixonic mixonic mentioned this pull request Jul 21, 2022
@mixonic mixonic force-pushed the mixonic/offsetHeight-is-int branch from f3eb2b4 to dfec26c Compare August 3, 2023 18:11
@mixonic mixonic mentioned this pull request Aug 3, 2023
8 tasks
@mixonic mixonic force-pushed the mixonic/offsetHeight-is-int branch 2 times, most recently from 56abd37 to 675d8fb Compare August 22, 2023 13:46
@mixonic mixonic force-pushed the mixonic/offsetHeight-is-int branch 9 times, most recently from f6e3a12 to 5e417a5 Compare August 23, 2023 16:22
@mixonic mixonic force-pushed the mixonic/offsetHeight-is-int branch from 5e417a5 to 6ebd499 Compare August 23, 2023 16:25
offsetHeight returns an integer, making it a poor API to base the
determination of element scale on. Instead, use an alternative and
precise API. Only allow a reasonable amount of precision by decimal
place, and for cases where the scale number is reasonably rounded do so.

The offsetHeight method includes padding in returned sizes, where
getComputedStyle does not. Check them against each other, and if they
diverge signifcantly (>1) throw an exception.

To make ember-table itself compatible with this appraoch, pass the
`scale` value around the system a bit more instead of trying to derive
it in many places.
@mixonic mixonic force-pushed the mixonic/offsetHeight-is-int branch from 6ebd499 to 3aed24a Compare August 23, 2023 16:27
@mixonic mixonic marked this pull request as ready for review August 23, 2023 17:19
@mixonic mixonic requested a review from a team August 23, 2023 17:21
@mixonic
Copy link
Member Author

mixonic commented Aug 24, 2023

I've confirmed in an internal codebase that this improves how well a table can match the intended container it is in. Landing it, and I'll but a beta/preview release for Ember Table v6 sometime soon.

@mixonic mixonic merged commit 2e07731 into master Aug 24, 2023
16 checks passed
@mixonic mixonic deleted the mixonic/offsetHeight-is-int branch August 24, 2023 21:23
@mixonic mixonic added the 6.0 label Aug 25, 2023
@mixonic
Copy link
Member Author

mixonic commented Aug 25, 2023

Released in v6.0.0-0 prerelease

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

3 participants