Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite table block to use a simpler RichText value #8767

Merged
merged 13 commits into from
Aug 23, 2018
40 changes: 5 additions & 35 deletions packages/block-library/src/table/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,8 @@ export default class TableEdit extends Component {
* @param {Array} content A RichText content value.
*/
onChange( content ) {
const { selectedCell } = this.state;

if ( ! selectedCell ) {
return;
}

const { attributes, setAttributes } = this.props;
const { section, rowIndex, columnIndex } = selectedCell;
const { section, rowIndex, columnIndex } = this.state.selectedCell;

setAttributes( updateCellContent( attributes, {
section,
Expand All @@ -130,14 +124,8 @@ export default class TableEdit extends Component {
* @param {number} delta Offset for selected row index at which to insert.
*/
onInsertRow( delta ) {
const { selectedCell } = this.state;

if ( ! selectedCell ) {
return;
}

const { attributes, setAttributes } = this.props;
const { section, rowIndex } = selectedCell;
const { section, rowIndex } = this.state.selectedCell;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, but selectedCell can still be null?

Copy link
Member

@gziolo gziolo Aug 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We check it when providing isDisabled for menu items, then they are disabled. In addition, I added return clause in the event callback.


this.setState( { selectedCell: null } );
setAttributes( insertRow( attributes, {
Expand All @@ -164,14 +152,8 @@ export default class TableEdit extends Component {
* Deletes the currently selected row.
*/
onDeleteRow() {
const { selectedCell } = this.state;

if ( ! selectedCell ) {
return;
}

const { attributes, setAttributes } = this.props;
const { section, rowIndex } = selectedCell;
const { section, rowIndex } = this.state.selectedCell;

this.setState( { selectedCell: null } );
setAttributes( deleteRow( attributes, { section, rowIndex } ) );
Expand All @@ -183,14 +165,8 @@ export default class TableEdit extends Component {
* @param {number} delta Offset for selected column index at which to insert.
*/
onInsertColumn( delta = 0 ) {
const { selectedCell } = this.state;

if ( ! selectedCell ) {
return;
}

const { attributes, setAttributes } = this.props;
const { section, columnIndex } = selectedCell;
const { section, columnIndex } = this.state.selectedCell;

this.setState( { selectedCell: null } );
setAttributes( insertColumn( attributes, {
Expand All @@ -217,14 +193,8 @@ export default class TableEdit extends Component {
* Deletes the currently selected column.
*/
onDeleteColumn() {
const { selectedCell } = this.state;

if ( ! selectedCell ) {
return;
}

const { attributes, setAttributes } = this.props;
const { section, columnIndex } = selectedCell;
const { section, columnIndex } = this.state.selectedCell;

this.setState( { selectedCell: null } );
setAttributes( deleteColumn( attributes, { section, columnIndex } ) );
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/dropdown-menu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ A human-readable label to present as accessibility text on the focused collapsed

An array of objects describing the options to be shown in the expanded menu.

Each object should include an `icon` [Dashicon](https://developer.wordpress.org/resource/dashicons/) slug string, a human-readable `title` string, and an `onClick` function callback to invoke when the option is selected.
Each object should include an `icon` [Dashicon](https://developer.wordpress.org/resource/dashicons/) slug string, a human-readable `title` string, `isDisabled` boolean flag and an `onClick` function callback to invoke when the option is selected.

- Type: `Array`
- Required: Yes
Expand Down
4 changes: 4 additions & 0 deletions packages/components/src/dropdown-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ function DropdownMenu( {
<IconButton
key={ index }
onClick={ ( event ) => {
if ( control.isDisabled ) {
return;
}
event.stopPropagation();
onClose();
if ( control.onClick ) {
Expand All @@ -77,6 +80,7 @@ function DropdownMenu( {
className="components-dropdown-menu__menu-item"
icon={ control.icon }
role="menuitem"
disabled={ control.isDisabled }
>
{ control.title }
</IconButton>
Expand Down