codex-team / codex-team/editor.js
How to catch Block's onFocus event simply
- Dominant language
- TypeScript
- Stars
- 31.9k
- Forks
- 2.2k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 1
Description
I think it is more useful to implement focus event in Editor.js !
To catch Block's onFocus event, it needs to use MutationObserver currently.
```
render() {
const container = document.createElement('div');
setTimeout(() => {
const block = container.parentElement && container.parentElement.parentElement;
if (block) {
// TODO: disconnect
const observer = new MutationObserver(() => {
console.log(block.classList);
});
observer.observe(block, {
attributeFilter: ['class'],
attributes: true,
});
}
}, 100);
return container;
}
```
console output
```
DOMTokenList ["ce-block", value: "ce-block"]
DOMTokenList(2) ["ce-block", "ce-block--focused", value: "ce-block ce-block--focused"]
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.