codex-team / codex-team/editor.js

How to catch Block's onFocus event simply

Open
#1,004 4 comments 2 reactions 0 assignees View on GitHub
good first issue
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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.