From 7ca5deebd3980fd32a1b2117b2d54151fa913341 Mon Sep 17 00:00:00 2001 From: bhsd <2545473905@qq.com> Date: Sat, 7 Dec 2024 13:58:11 +0800 Subject: [PATCH] CodeMirrorPanel: specify `type="button"` for ToggleButton A button without the `type` attribute in a form is assumed to be the submit button. Obviously, the toggle buttons in a CM6 panel should not be one. Bug: T381713 Change-Id: Ia732d49a3a61f85dd264d287ddd066b4d93e90c3 --- resources/codemirror.panel.js | 1 + tests/jest/codemirror.panel.test.js | 2 ++ 2 files changed, 3 insertions(+) diff --git a/resources/codemirror.panel.js b/resources/codemirror.panel.js index 77978921..e78122b9 100644 --- a/resources/codemirror.panel.js +++ b/resources/codemirror.panel.js @@ -167,6 +167,7 @@ class CodeMirrorPanel { // * cdx-toggle-button--toggled-off btn.className = 'cdx-toggle-button cdx-toggle-button--framed ' + `cdx-toggle-button--toggled-${ checked ? 'on' : 'off' } cm-mw-panel--toggle-button`; + btn.type = 'button'; btn.dataset.checked = String( checked ); btn.setAttribute( 'aria-pressed', checked ); // The following messages may be used here: diff --git a/tests/jest/codemirror.panel.test.js b/tests/jest/codemirror.panel.test.js index 9bf4974c..91ede72c 100644 --- a/tests/jest/codemirror.panel.test.js +++ b/tests/jest/codemirror.panel.test.js @@ -75,6 +75,7 @@ describe( 'CodeMirrorPanel', () => { expect( toggleButtonOn.className ).toBe( 'cdx-toggle-button cdx-toggle-button--framed cdx-toggle-button--toggled-on cm-mw-panel--toggle-button' ); + expect( toggleButtonOn.type ).toBe( 'button' ); expect( toggleButtonOn.dataset.checked ).toBe( 'true' ); expect( toggleButtonOn.getAttribute( 'aria-pressed' ) ).toBe( 'true' ); expect( toggleButtonOn.title ).toBe( 'bar' ); @@ -88,6 +89,7 @@ describe( 'CodeMirrorPanel', () => { expect( toggleButtonOff.className ).toBe( 'cdx-toggle-button cdx-toggle-button--framed cdx-toggle-button--toggled-off cm-mw-panel--toggle-button' ); + expect( toggleButtonOff.type ).toBe( 'button' ); expect( toggleButtonOff.dataset.checked ).toBe( 'false' ); expect( toggleButtonOff.getAttribute( 'aria-pressed' ) ).toBe( 'false' ); } );