Skip to content

Commit 2beb9ff

Browse files
authored
Add focus_in and focus_out events (#19)
1 parent 6dd71d4 commit 2beb9ff

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

src/renderview.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,11 @@ class BaseRenderView {
437437
if (this.wrapperElement) {
438438
this.wrapperElement.classList.add('has-focus')
439439
}
440-
// at the moment the spec does not define focus and blur events, so only used internally for styling purposeses
440+
const event = {
441+
type: 'focus_in',
442+
timestamp: getTimestamp()
443+
}
444+
this.onEvent(event)
441445
},
442446
{ signal }
443447
)
@@ -446,6 +450,11 @@ class BaseRenderView {
446450
if (this.wrapperElement) {
447451
this.wrapperElement.classList.remove('has-focus')
448452
}
453+
const event = {
454+
type: 'focus_out',
455+
timestamp: getTimestamp()
456+
}
457+
this.onEvent(event)
449458
},
450459
{ signal }
451460
)

src/spec.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
A protocol for interactive rendering surfaces.
55

6-
*Last update: 19-03-2026*
6+
*Last update: 03-04-2026*
77

88
*This spec was previously known as the jupyter_rfb event spec, but was rolled into a separate project.*
99

@@ -106,6 +106,26 @@ Fields:
106106
* `timestamp`: A timestamp in seconds.
107107

108108

109+
### focus_in
110+
111+
This event emitted when the canvas receives focus and can now receive key events.
112+
113+
Fields:
114+
115+
* `type`: 'focus_in'
116+
* `timestamp`: A timestamp in seconds.
117+
118+
119+
### focus_out
120+
121+
This event emitted when the canvas loses focus (a.k.a. blur) and can no longer receive key events.
122+
123+
Fields:
124+
125+
* `type`: 'focus_out'
126+
* `timestamp`: A timestamp in seconds.
127+
128+
109129
### pointer_down
110130

111131
This event is emitted when the user interacts with mouse, touch or other pointer devices, by pressing it down.
@@ -308,6 +328,12 @@ To avoid straining the IO, certain events can be throttled. Their effect
308328
is accumulated if this makes sense(e.g. wheel event).
309329

310330

331+
## Changelog
332+
333+
* 03-04-2026: add 'focus_in' and 'focus_out' events.
334+
* 18-03-2026: add 'show' and 'hide' events.
335+
* 18-03-2026: create this document starting from a copy of the Jupyter event spec.
336+
311337

312338
<br><br>
313339

0 commit comments

Comments
 (0)