editor.js icon indicating copy to clipboard operation
editor.js copied to clipboard

<select /> not triggering editor.onChange (Old bug resurfaced)

Open moomoo-dev opened this issue 10 months ago • 6 comments

I'm trying to use a select in a block and it's not triggering the onchange event.

Steps to reproduce: I took the example from this page, and it's not working.

Expected behavior:

Screenshots:

Device, Browser, OS: Mac, Chrome, 15.6 (24G84)

Editor.js version: @editorjs/[email protected]

Plugins you use with their versions:

I even used the example on the page and it still not working.

export default class SelectMenu { static get toolbox() { return {

  title: 'Select',
  icon: '<svg width="17" height="15" viewBox="0 0 336 276" xmlns="http://www.w3.org/2000/svg"><path d="M291 150V79c0-19-15-34-34-34H79c-19 0-34 15-34 34v42l67-44 81 72 56-29 42 30zm0 52l-43-30-56 30-81-67-66 39v23c0 19 15 34 34 34h178c17 0 31-13 34-29zM79 0h178c44 0 79 35 79 79v118c0 44-35 79-79 79H79c-44 0-79-35-79-79V79C0 35 35 0 79 0z"/></svg>'
};

}

constructor({ data }) { this.data = data; }

render() { const wrapper = document.createElement('div'); const input = document.createElement('select');

var option = document.createElement("option");
option.setAttribute("value", "option1");
var textOption = document.createTextNode("option1");
option.appendChild(textOption);
input.appendChild(option);

option = document.createElement("option");
option.setAttribute("value", "option2");
textOption = document.createTextNode("option2");
option.appendChild(textOption);
input.appendChild(option);

option = document.createElement("option");
option.setAttribute("value", "option3");
textOption = document.createTextNode("option3");
option.appendChild(textOption);
input.appendChild(option);
wrapper.appendChild(input);

return wrapper;

}

save(blockContent) { const input = blockContent.querySelector('select');

return {
  selectValue: input.value
}

} }

moomoo-dev avatar Jan 09 '26 03:01 moomoo-dev

Here is the old bug https://github.com/codex-team/editor.js/issues/1027

moomoo-dev avatar Jan 09 '26 03:01 moomoo-dev

Hi, I reproduced this issue and found Sion612’s fork-local PR #1, which adds regression tests but does not include a core fix. I’d like to continue investigating the implementation on the upstream next branch, building on those test cases. Please let me know if anyone is actively working on this.

Sawtone avatar Sep 11 '26 07:09 Sawtone

Hi, I reproduced this issue and found Sion612’s fork-local PR #1, which adds regression tests but does not include a core fix. I’d like to continue investigating the implementation on the upstream next branch, building on those test cases. Please let me know if anyone is actively working on this.

Hey, @Sawtone . Feel free to do that

neSpecc avatar Sep 11 '26 16:09 neSpecc

Hi @Sawtone and @neSpecc —quick update from my side.

I’m the author of the fork-local regression tests you referenced..I’ve now finished a minimal candidate fix locally against next, covering native <select> change notifications and the deferred Block-listener cleanup during destruction.

The focused Cypress spec now passes 28/28 with the fix, including the teardown regression case.

I haven’t opened an upstream PR because I don’t want to duplicate your work. I’m happy to share the patch and tests with you, or I can submit the upstream PR if you’d prefer. Let me know which direction works better for you.

Sion612 avatar Sep 14 '26 14:09 Sion612

Hi @Sion612, thanks for the update and for your earlier regression tests!

I also have a candidate fix ready, now pushed to my fork. I reused and extended your fixture and tests, with attribution in the commit.

The implementation delegates select changes to the Block holder during bubbling, registers the listener synchronously, and removes it on destruction. All 30 tests in onchange.cy.ts passed locally with Cypress/Electron against a temporary Vite source fixture.

I have opened an upstream PR #3025 so the maintainers can review the implementation. Please feel free to share your candidate patch or PR as well. We can compare approaches and select or combine them according to the maintainers’ preference. Thanks for coordinating this!

Sawtone avatar Sep 15 '26 08:09 Sawtone

@Sawtone Thanks for the update and for the attribution! I’ll follow #3025, and I’m happy to share my patch or compare approaches if that would be useful during review.

Sion612 avatar Sep 16 '26 05:09 Sion612