Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to catch Block's onFocus event simply #1004

Open
hata6502 opened this issue Jan 8, 2020 · 1 comment
Open

How to catch Block's onFocus event simply #1004

hata6502 opened this issue Jan 8, 2020 · 1 comment

Comments

@hata6502
Copy link
Contributor

@hata6502 hata6502 commented Jan 8, 2020

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"]
@theevilhead
Copy link

@theevilhead theevilhead commented Jan 28, 2020

If I am getting this right, listening for a focus event on a contentEditable block should help out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.