Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #242 from ckeditor/i/6227
Browse files Browse the repository at this point in the history
Internal: Setting table/cell border style to "none" should reset other border fields. Closes ckeditor/ckeditor5#6227.
  • Loading branch information
oleq authored Feb 12, 2020
2 parents 717608c + 08f05f6 commit 5726090
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 59 deletions.
65 changes: 37 additions & 28 deletions src/tablecellproperties/ui/tablecellpropertiesview.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,34 +62,6 @@ export default class TableCellPropertiesView extends View {
constructor( locale ) {
super( locale );

const { borderStyleDropdown, borderWidthInput, borderColorInput, borderRowLabel } = this._createBorderFields();
const { widthInput, operatorLabel, heightInput, dimensionsLabel } = this._createDimensionFields();
const { horizontalAlignmentToolbar, verticalAlignmentToolbar, alignmentLabel } = this._createAlignmentFields();

/**
* Tracks information about the DOM focus in the form.
*
* @readonly
* @member {module:utils/focustracker~FocusTracker}
*/
this.focusTracker = new FocusTracker();

/**
* An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
*
* @readonly
* @member {module:utils/keystrokehandler~KeystrokeHandler}
*/
this.keystrokes = new KeystrokeHandler();

/**
* A collection of child views in the form.
*
* @readonly
* @type {module:ui/viewcollection~ViewCollection}
*/
this.children = this.createCollection();

this.set( {
/**
* The value of the cell border style.
Expand Down Expand Up @@ -173,6 +145,34 @@ export default class TableCellPropertiesView extends View {
verticalAlignment: 'middle'
} );

const { borderStyleDropdown, borderWidthInput, borderColorInput, borderRowLabel } = this._createBorderFields();
const { widthInput, operatorLabel, heightInput, dimensionsLabel } = this._createDimensionFields();
const { horizontalAlignmentToolbar, verticalAlignmentToolbar, alignmentLabel } = this._createAlignmentFields();

/**
* Tracks information about the DOM focus in the form.
*
* @readonly
* @member {module:utils/focustracker~FocusTracker}
*/
this.focusTracker = new FocusTracker();

/**
* An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
*
* @readonly
* @member {module:utils/keystrokehandler~KeystrokeHandler}
*/
this.keystrokes = new KeystrokeHandler();

/**
* A collection of child views in the form.
*
* @readonly
* @type {module:ui/viewcollection~ViewCollection}
*/
this.children = this.createCollection();

/**
* A dropdown that allows selecting the style of the table cell border.
*
Expand Down Expand Up @@ -494,6 +494,15 @@ export default class TableCellPropertiesView extends View {
this.borderColor = borderColorInput.view.element.value;
} );

// Reset the border color and width fields when style is "none".
// https://github.com/ckeditor/ckeditor5/issues/6227
this.on( 'change:borderStyle', ( evt, name, value ) => {
if ( value === 'none' ) {
this.borderColor = '';
this.borderWidth = '';
}
} );

return {
borderRowLabel,
borderStyleDropdown,
Expand Down
67 changes: 38 additions & 29 deletions src/tableproperties/ui/tablepropertiesview.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,34 +54,6 @@ export default class TablePropertiesView extends View {
constructor( locale ) {
super( locale );

const { borderStyleDropdown, borderWidthInput, borderColorInput, borderRowLabel } = this._createBorderFields();
const { widthInput, operatorLabel, heightInput, dimensionsLabel } = this._createDimensionFields();
const { alignmentToolbar, alignmentLabel } = this._createAlignmentFields();

/**
* Tracks information about the DOM focus in the form.
*
* @readonly
* @member {module:utils/focustracker~FocusTracker}
*/
this.focusTracker = new FocusTracker();

/**
* An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
*
* @readonly
* @member {module:utils/keystrokehandler~KeystrokeHandler}
*/
this.keystrokes = new KeystrokeHandler();

/**
* A collection of child views in the form.
*
* @readonly
* @type {module:ui/viewcollection~ViewCollection}
*/
this.children = this.createCollection();

this.set( {
/**
* The value of the border style.
Expand Down Expand Up @@ -147,6 +119,34 @@ export default class TablePropertiesView extends View {
alignment: ''
} );

const { borderStyleDropdown, borderWidthInput, borderColorInput, borderRowLabel } = this._createBorderFields();
const { widthInput, operatorLabel, heightInput, dimensionsLabel } = this._createDimensionFields();
const { alignmentToolbar, alignmentLabel } = this._createAlignmentFields();

/**
* Tracks information about the DOM focus in the form.
*
* @readonly
* @member {module:utils/focustracker~FocusTracker}
*/
this.focusTracker = new FocusTracker();

/**
* An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
*
* @readonly
* @member {module:utils/keystrokehandler~KeystrokeHandler}
*/
this.keystrokes = new KeystrokeHandler();

/**
* A collection of child views in the form.
*
* @readonly
* @type {module:ui/viewcollection~ViewCollection}
*/
this.children = this.createCollection();

/**
* A dropdown that allows selecting the style of the table border.
*
Expand Down Expand Up @@ -440,11 +440,20 @@ export default class TablePropertiesView extends View {
this.borderColor = borderColorInput.view.element.value;
} );

// Reset the border color and width fields when style is "none".
// https://github.com/ckeditor/ckeditor5/issues/6227
this.on( 'change:borderStyle', ( evt, name, value ) => {
if ( value === 'none' ) {
this.borderColor = '';
this.borderWidth = '';
}
} );

return {
borderRowLabel,
borderStyleDropdown,
borderColorInput,
borderWidthInput,
borderWidthInput
};
}

Expand Down
13 changes: 12 additions & 1 deletion tests/tablecellproperties/ui/tablecellpropertiesview.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,20 @@ describe( 'table cell properties', () => {
expect( labeledDropdown.view.listView.items.map( item => {
return item.children.first.label;
} ) ).to.have.ordered.members( [
'None', 'Solid', 'Dotted', 'Dashed', 'Double', 'Groove', 'Ridge', 'Inset', 'Outset',
'None', 'Solid', 'Dotted', 'Dashed', 'Double', 'Groove', 'Ridge', 'Inset', 'Outset'
] );
} );

it( 'should reset border width and color inputs when setting style to none', () => {
view.borderStyle = 'dotted';
view.borderWidth = '1px';
view.borderColor = 'red';

view.borderStyle = 'none';

expect( view.borderColor ).to.equal( '' );
expect( view.borderWidth ).to.equal( '' );
} );
} );

describe( 'border width input', () => {
Expand Down
13 changes: 12 additions & 1 deletion tests/tableproperties/ui/tablepropertiesview.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,20 @@ describe( 'table properties', () => {
expect( labeledDropdown.view.listView.items.map( item => {
return item.children.first.label;
} ) ).to.have.ordered.members( [
'None', 'Solid', 'Dotted', 'Dashed', 'Double', 'Groove', 'Ridge', 'Inset', 'Outset',
'None', 'Solid', 'Dotted', 'Dashed', 'Double', 'Groove', 'Ridge', 'Inset', 'Outset'
] );
} );

it( 'should reset border width and color inputs when setting style to none', () => {
view.borderStyle = 'dotted';
view.borderWidth = '1px';
view.borderColor = 'red';

view.borderStyle = 'none';

expect( view.borderColor ).to.equal( '' );
expect( view.borderWidth ).to.equal( '' );
} );
} );

describe( 'border width input', () => {
Expand Down

0 comments on commit 5726090

Please sign in to comment.