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
This commit is contained in:
bhsd 2024-12-07 13:58:11 +08:00
parent e75ca66a66
commit 7ca5deebd3
2 changed files with 3 additions and 0 deletions

View file

@ -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:

View file

@ -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' );
} );