-
Notifications
You must be signed in to change notification settings - Fork 22.6k
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
Conversation
Preview URLs(this comment was updated 2022-09-09 16:07:19.322311) |
There was a problem hiding this 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
draggableElement.addEventListener("dragstart", (event) => | ||
event.dataTransfer.setData("text/plain", "This text may be dragged") | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
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"); | |
}); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No strong feelings here.
```js | ||
const draggableElement = document.querySelector('p[draggable="true"]'); | ||
draggableElement.addEventListener("dragstart", (event) => | ||
event.dataTransfer.setData("text/plain", "This text may be dragged") | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
```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"); | |
}); |
files/en-us/web/api/html_drag_and_drop_api/drag_operations/index.md
Outdated
Show resolved
Hide resolved
…ex.md Co-authored-by: Jean-Yves Perrier <jypenator@gmail.com>
* 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>
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:
:-moz-drag-over
and XUL(!))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.