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

Fixes to drag operations page #20403

Merged
merged 4 commits into from
Sep 12, 2022
Merged

Fixes to drag operations page #20403

merged 4 commits into from
Sep 12, 2022

Conversation

wbamberg
Copy link
Collaborator

@wbamberg wbamberg commented Sep 7, 2022

Description

Rewrite the page to use addEventListener rather than HTML event attributes, and have a better example in "Specifying drop targets". This PR replaces #20048.

But also a bit of yak-shaving:

  • remove some Firefox-only stuff (:-moz-drag-over and XUL(!))
  • sentence case for headings

I used Prettier so it has also reformatted other code samples. I hope that is OK.

Motivation

Better practice code samples.

Related issues and pull requests

Relates to #20048.

@wbamberg wbamberg requested a review from a team as a code owner September 7, 2022 20:47
@wbamberg wbamberg requested review from jpmedley and removed request for a team September 7, 2022 20:47
@github-actions github-actions bot added the Content:WebAPI Web API docs label Sep 7, 2022
@wbamberg wbamberg mentioned this pull request Sep 7, 2022
3 tasks
@github-actions
Copy link
Contributor

github-actions bot commented Sep 7, 2022

Preview URLs

(this comment was updated 2022-09-09 16:07:19.322311)

Copy link
Contributor

@teoli2003 teoli2003 left a comment

Choose a reason for hiding this comment

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

A few nit, and a problem at doDrop

Comment on lines +39 to +41
draggableElement.addEventListener("dragstart", (event) =>
event.dataTransfer.setData("text/plain", "This text may be dragged")
);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
draggableElement.addEventListener("dragstart", (event) =>
event.dataTransfer.setData("text/plain", "This text may be dragged")
);
draggableElement.addEventListener("dragstart", (event) => {
event.dataTransfer.setData("text/plain", "This text may be dragged");
});

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is interesting and I'm not sure what the right thing to do is. I wrote:

draggableElement.addEventListener("dragstart", (event) => event.dataTransfer.setData("text/plain", "This text may be dragged"));

(which is fine AFAIK) but which Prettier auto-formatted to:

draggableElement.addEventListener("dragstart", (event) =>
  event.dataTransfer.setData("text/plain", "This text may be dragged")
);

So if we want to rely on Prettier auto-formatting, then we should not make your suggested change.

Copy link
Contributor

@teoli2003 teoli2003 Sep 9, 2022

Choose a reason for hiding this comment

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

If you had written:

draggableElement.addEventListener("dragstart", (event) => { event.dataTransfer.setData("text/plain", "This text may be dragged");});

The results would have been:

draggableElement.addEventListener("dragstart", (event) => {
  event.dataTransfer.setData("text/plain", "This text may be dragged");
});

So the question here is not Prettier formatting, but do we add braces when there is only one operation and no (real) return value (ok, it returns something, but not useful here)? We recommend using consise body (or implicit return) with arrow functions when possible, but is this the case?

(We skipped this question while reviewing the JS guidelines)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If you had written:

draggableElement.addEventListener("dragstart", (event) => { event.dataTransfer.setData("text/plain", "This text may be dragged");});

The results would have been:

draggableElement.addEventListener("dragstart", (event) => {
  event.dataTransfer.setData("text/plain", "This text may be dragged");
});

So the question here is not Prettier formatting, but do we add braces when there is only one operation and no (real) return value (ok, it returns something, but not useful here)? We recommend using consise body (or implicit return) with arrow functions when possible, but is this the case?

Do you mean, is it possible? Of course it is.

But it doesn't matter whether we use the return or not. If my code had been:

const myItemsWithALongEnoughName = [1, 2, 3, 4];
const filteredWithALongEnoughName = myItemsWithALongEnoughName.filter((item) => item < 3);

console.log(filteredWithALongEnoughName);

...then Prettier would do:

const myItemsWithALongEnoughName = [1, 2, 3, 4];
const filteredWithALongEnoughName = myItemsWithALongEnoughName.filter(
  (item) => item < 3
);

console.log(filteredWithALongEnoughName);

It's just wrapping lines.

So the question is: do we say you can't use the concise form if it would give you a line long enough for Prettier to wrap? I don't think we should do this, because it goes against the idea of using Prettier, which is basically: you don't have to worry about what Prettier will do, or have any knowledge of its config.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So I think we should allow (maybe even encourage) people to use to use the concise form if it's allowed, and allow Prettier's wrapping if Prettier decides to wrap.

Copy link
Contributor

Choose a reason for hiding this comment

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

No strong feelings here.

Comment on lines +58 to +62
```js
const draggableElement = document.querySelector('p[draggable="true"]');
draggableElement.addEventListener("dragstart", (event) =>
event.dataTransfer.setData("text/plain", "This text may be dragged")
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
```js
const draggableElement = document.querySelector('p[draggable="true"]');
draggableElement.addEventListener("dragstart", (event) =>
event.dataTransfer.setData("text/plain", "This text may be dragged")
);
```js
const draggableElement = document.querySelector('p[draggable="true"]');
draggableElement.addEventListener("dragstart", (event) => {
event.dataTransfer.setData("text/plain", "This text may be dragged");
});

…ex.md

Co-authored-by: Jean-Yves Perrier <jypenator@gmail.com>
@teoli2003 teoli2003 merged commit 6718ec2 into mdn:main Sep 12, 2022
himanshugarg pushed a commit to himanshugarg/content that referenced this pull request Sep 27, 2022
* Fixes to drag operations page

* Fix a typo

* Fix page title

* Update files/en-us/web/api/html_drag_and_drop_api/drag_operations/index.md

Co-authored-by: Jean-Yves Perrier <jypenator@gmail.com>

Co-authored-by: Jean-Yves Perrier <jypenator@gmail.com>
@wbamberg wbamberg deleted the fix-drag-events branch April 5, 2023 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:WebAPI Web API docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants