Skip to content

Commit

Permalink
Componnet: Add isDisabled support for DropdownMenu controls
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Aug 23, 2018
1 parent 7b59b4b commit 19b7cb3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 36 deletions.
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;

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

0 comments on commit 19b7cb3

Please sign in to comment.