Skip to content

Commit da9d759

Browse files
authored
Merge pull request #392 from brentguf/mouse-events-basics
Mouse Events Chapter
2 parents 4918bdd + 317c89a commit da9d759

File tree

1 file changed

+8
-8
lines changed
  • 2-ui/3-event-details/1-mouse-events-basics

1 file changed

+8
-8
lines changed

2-ui/3-event-details/1-mouse-events-basics/article.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Also we can see the `which` property that allows to detect the mouse button.
5656

5757
## Getting the button: which
5858

59-
Click-related events always have the `which` property that allows to get the button.
59+
Click-related events always have the `which` property, which allows to get the exact mouse button.
6060

6161
It is not used for `click` and `contextmenu` events, because the former happens only on left-click, and the latter -- only on right-click.
6262

@@ -175,7 +175,7 @@ Now if you double-click on "Unselectable", it doesn't get selected. Seems to wor
175175

176176
...But there is a potential problem! The text became truly unselectable. Even if a user starts the selection from "Before" and ends with "After", the selection skips "Unselectable" part. Do we really want to make our text unselectable?
177177

178-
Most of time, we don't. A user may have valid reasons to select the text, for copying or other needs. That may be disturbing if we don't allow him to do it. So the solution is not that good.
178+
Most of time, we don't. A user may have valid reasons to select the text, for copying or other needs. That may be inconvenient if we don't allow him to do it. So this solution is not that good.
179179

180180
What we want is to prevent the selection on double-click, that's it.
181181

@@ -191,7 +191,7 @@ Before...
191191

192192
Now the bold element is not selected on double clicks.
193193

194-
From the other hand, the text inside it is still selectable. The selection should start not on the text itself, but before or after it. Usually that's fine.
194+
The text inside it is still selectable. However, the selection should start not on the text itself, but before or after it. Usually that's fine though.
195195

196196
````smart header="Canceling the selection"
197197
Instead of *preventing* the selection, we can cancel it "post-factum" in the event handler.
@@ -226,18 +226,18 @@ Surely that can't stop the user from opening HTML-source, but not everyone knows
226226

227227
## Summary
228228

229-
Mouse events have following properties:
229+
Mouse events have the following properties:
230230

231231
- Button: `which`.
232232
- Modifier keys (`true` if pressed): `altKey`, `ctrlKey`, `shiftKey` and `metaKey` (Mac).
233233
- If you want to handle `key:Ctrl`, then don't forget Mac users, they use `key:Cmd`, so it's better to check `if (e.metaKey || e.ctrlKey)`.
234234

235235
- Window-relative coordinates: `clientX/clientY`.
236-
- Document-relative coordinates: `pageX/clientX`.
236+
- Document-relative coordinates: `pageX/pageY`.
237237

238-
In the tasks below it's also important to deal with the selection as an unwanted side-effect of clicks.
238+
It's also important to deal with text selection as an unwanted side-effect of clicks.
239239

240-
There are several ways, for instance:
241-
1. CSS-property `user-select:none` (with browser prefixes) completely disables it.
240+
There are several ways to do this, for instance:
241+
1. The CSS-property `user-select:none` (with browser prefixes) completely disables text-selection.
242242
2. Cancel the selection post-factum using `getSelection().removeAllRanges()`.
243243
3. Handle `mousedown` and prevent the default action (usually the best).

0 commit comments

Comments
 (0)