8
0
فهرست منبع

Added: Do not fire "execute" on disabled list item.

Maciej Gołaszewski 7 سال پیش
والد
کامیت
17e3f0e451
2فایلهای تغییر یافته به همراه22 افزوده شده و 1 حذف شده
  1. 11 1
      packages/ckeditor5-ui/src/list/listitemview.js
  2. 11 0
      packages/ckeditor5-ui/tests/list/listitemview.js

+ 11 - 1
packages/ckeditor5-ui/src/list/listitemview.js

@@ -63,7 +63,17 @@ export default class ListItemView extends View {
 			],
 
 			on: {
-				click: bind.to( 'execute' )
+				click: bind.to( evt => {
+					// We can't make the button disabled using the disabled attribute, because it won't be focusable.
+					// Though, shouldn't this condition be moved to the button controller?
+					if ( this.isEnabled ) {
+						this.fire( 'execute' );
+					} else {
+						// Prevent the default when button is disabled, to block e.g.
+						// automatic form submitting. See ckeditor/ckeditor5-link#74.
+						evt.preventDefault();
+					}
+				} )
 			}
 		} );
 

+ 11 - 0
packages/ckeditor5-ui/tests/list/listitemview.js

@@ -146,6 +146,17 @@ describe( 'ListItemView', () => {
 				view.element.dispatchEvent( new Event( 'click' ) );
 				expect( spy.calledOnce ).to.be.true;
 			} );
+
+			it( 'does not triggers view#execute event when "click" is fired in DOM and isEnables=false', () => {
+				const spy = sinon.spy();
+
+				view.on( 'execute', spy );
+
+				view.isEnabled = false;
+
+				view.element.dispatchEvent( new Event( 'click' ) );
+				sinon.assert.notCalled( spy );
+			} );
 		} );
 	} );