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

Added position related APIs. #705

Merged
merged 2 commits into from
Nov 18, 2024
Merged

Added position related APIs. #705

merged 2 commits into from
Nov 18, 2024

Conversation

gdotdesign
Copy link
Member

Added:

  • Dom.offsetLeft, Dom.offsetTop methods
  • Html.Event.layerX, Html.Event.layerY fields
  • Html.Event.offsetX, Html.Event.offsetY fields

Fixes #498

@gdotdesign gdotdesign added the enhancement New feature or request label Nov 16, 2024
@gdotdesign gdotdesign added this to the 0.21.0 milestone Nov 16, 2024
@gdotdesign gdotdesign requested a review from Sija November 16, 2024 12:37
@gdotdesign gdotdesign self-assigned this Nov 16, 2024
}
*/
fun offsetLeft (element : Dom.Element) : Number {
`#{element}.offsetLeft || -1`
Copy link
Member

Choose a reason for hiding this comment

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

Returning -1 is here is IMO totally unexpected and may lead to hard-to-debug bugs.
Also, AFAIU it's not coherent with this method documentation.

ditto below

Copy link
Member Author

Choose a reason for hiding this comment

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

We have other functions that return values similarly https://github.com/mint-lang/mint/blob/master/core/source/Dom.mint#L371 https://github.com/mint-lang/mint/blob/dom-position-things/runtime/src/normalize_event.js#L93 We could return Maybe(Number) (and for all similar functions) but it would greatly increase the friction when using this.

I'll update the documentation comment to reflect this.

Copy link
Member Author

Choose a reason for hiding this comment

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

If the element is not in the DOM, it returns 0:

document.createElement("div").offsetLeft

So maybe returning 0 if it's not applicable is better?

Copy link
Member

Choose a reason for hiding this comment

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

0 sounds better to me, although it still seems more like a hack tbh...

Copy link
Member

Choose a reason for hiding this comment

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

I guess it's good for now, yet it needs to be changed for other props as well.

- `Dom.offsetLeft`, `Dom.offsetTop`
- `Html.Event.layerX`, `Html.Event.layerY`
- `Html.Event.offsetX`, `Html.Event.offsetY`

Fixes #498
@gdotdesign gdotdesign requested a review from Sija November 17, 2024 11:42
@gdotdesign gdotdesign merged commit 3205d9a into master Nov 18, 2024
3 checks passed
@gdotdesign gdotdesign deleted the dom-position-things branch November 18, 2024 05:26
Comment on lines +105 to +112
case "layerX":
return -1;
case "layerY":
return -1;
case "offsetX":
return -1;
case "offsetY":
return -1;
Copy link
Member

Choose a reason for hiding this comment

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

Aren't these need to be changed (to 0) as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

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

Successfully merging this pull request may close these issues.

Include/Implement Dom.offsetLeft or Html.Event.layerX or Html.Event.offsetX
2 participants