Skip to content

Commit 9aa0412

Browse files
committed
Update "Focusing: focus/blur" files
1 parent 735d8e3 commit 9aa0412

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

2-ui/4-forms-controls/2-focus-blur/3-editable-div/solution.view/my.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
}
2121

2222
.edit:focus {
23-
outline: none;
2423
/* remove focus border in Safari */
24+
outline: none;
2525
}

2-ui/4-forms-controls/2-focus-blur/3-editable-div/source.view/my.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
}
2121

2222
.edit:focus {
23-
outline: none;
2423
/* remove focus border in Safari */
24+
outline: none;
2525
}

2-ui/4-forms-controls/2-focus-blur/4-edit-td-click/solution.view/my.css

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
margin: 0;
44
padding: 0;
55
display: block;
6-
resize: none;
6+
77
/* remove resizing handle in Firefox */
8+
resize: none;
89

9-
outline: none;
1010
/* remove outline on focus in Chrome */
11+
outline: none;
1112

12-
overflow: auto;
1313
/* remove scrollbar in IE */
14+
overflow: auto;
1415
}
1516

1617
.edit-controls {

2-ui/4-forms-controls/2-focus-blur/5-keyboard-mouse/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
We can use `mouse.onclick` to handle the click and make the mouse "moveable" with `position:fixed`, then then `mouse.onkeydown` to handle arrow keys.
2+
We can use `mouse.onclick` to handle the click and make the mouse "moveable" with `position:fixed`, then `mouse.onkeydown` to handle arrow keys.
33

44
The only pitfall is that `keydown` only triggers on elements with focus. So we need to add `tabindex` to the element. As we're forbidden to change HTML, we can use `mouse.tabIndex` property for that.
55

2-ui/4-forms-controls/2-focus-blur/article.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
An element receives the focus when the user either clicks on it or uses the `key:Tab` key on the keyboard. There's also an `autofocus` HTML attribute that puts the focus onto an element by default when a page loads and other means of getting the focus.
44

5-
Focusing generally means: "prepare to accept the data here", so that's the moment when we can run the code to initialize or load something.
5+
Focusing on an element generally means: "prepare to accept the data here", so that's the moment when we can run the code to initialize the required functionality.
66

77
The moment of losing the focus ("blur") can be even more important. That's when a user clicks somewhere else or presses `key:Tab` to go to the next form field, or there are other means as well.
88

99
Losing the focus generally means: "the data has been entered", so we can run the code to check it or even to save it to the server and so on.
1010

11-
There are important peculiarities when working with focus events. We'll do the best to cover them here.
11+
There are important peculiarities when working with focus events. We'll do the best to cover them further on.
1212

1313
## Events focus/blur
1414

@@ -90,6 +90,8 @@ If we enter something into the input and then try to use `key:Tab` or click away
9090

9191
Please note that we can't "prevent losing focus" by calling `event.preventDefault()` in `onblur`, because `onblur` works *after* the element lost the focus.
9292

93+
In practice though, one should think well, before implementing something like this, because we generally *should show errors* to the user, but *should not prevent their progress* in filling our form. They may want to fill other fields first.
94+
9395
```warn header="JavaScript-initiated focus loss"
9496
A focus loss can occur for many reasons.
9597
@@ -208,7 +210,6 @@ So here's another working variant:
208210

209211
<script>
210212
*!*
211-
// put the handler on capturing phase (last argument true)
212213
form.addEventListener("focusin", () => form.classList.add('focused'));
213214
form.addEventListener("focusout", () => form.classList.remove('focused'));
214215
*/!*

0 commit comments

Comments
 (0)