Skip to content

Commit

Permalink
Remove ARIA roles and arrows navigation.
Browse files Browse the repository at this point in the history
  • Loading branch information
afercia committed May 31, 2018
1 parent c93b778 commit 68387c2
Showing 1 changed file with 2 additions and 53 deletions.
55 changes: 2 additions & 53 deletions editor/components/inserter/item-list.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,28 @@
/**
* External dependencies
*/
import { isEqual } from 'lodash';
import classnames from 'classnames';

/**
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import { NavigableMenu } from '@wordpress/components';
import { getBlockMenuDefaultClassName } from '@wordpress/blocks';

/**
* Internal dependencies
*/
import BlockIcon from '../block-icon';

function deriveActiveItems( items ) {
return items.filter( ( item ) => ! item.isDisabled );
}

class ItemList extends Component {
constructor() {
super( ...arguments );
this.onNavigate = this.onNavigate.bind( this );
this.activeItems = deriveActiveItems( this.props.items );
this.state = {
current: this.activeItems.length > 0 ? this.activeItems[ 0 ] : null,
};
}

componentDidUpdate( prevProps ) {
if ( ! isEqual( this.props.items, prevProps.items ) ) {
this.activeItems = deriveActiveItems( this.props.items );

// Try and preserve any still valid selected state.
const currentIsStillActive = this.state.current && this.activeItems.some( ( item ) =>
item.id === this.state.current.id
);

if ( ! currentIsStillActive ) {
this.setState( {
current: this.activeItems.length > 0 ? this.activeItems[ 0 ] : null,
} );
}
}
}

onNavigate( index ) {
const { activeItems } = this;
const dest = activeItems[ index ];
if ( dest ) {
this.setState( {
current: dest,
} );
}
}

render() {
const { items, onSelect, onHover } = this.props;
const { current } = this.state;

return (
<NavigableMenu
className="editor-inserter__item-list"
orientation="both"
cycle={ false }
onNavigate={ this.onNavigate }
>
<div className="editor-inserter__item-list">
{ items.map( ( item ) => {
const isCurrent = current && current.id === item.id;
return (
<button
role="menuitem"
key={ item.id }
className={
classnames(
Expand All @@ -84,7 +34,6 @@ class ItemList extends Component {
)
}
onClick={ () => onSelect( item ) }
tabIndex={ isCurrent || item.isDisabled ? null : '-1' }
disabled={ item.isDisabled }
onMouseEnter={ () => onHover( item ) }
onMouseLeave={ () => onHover( null ) }
Expand All @@ -102,7 +51,7 @@ class ItemList extends Component {
</button>
);
} ) }
</NavigableMenu>
</div>
);
}
}
Expand Down

0 comments on commit 68387c2

Please sign in to comment.