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

Blocks: Avoid autofocus behavior for blocks without focusable elements #5110

Merged
merged 4 commits into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion editor/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ export class BlockListBlock extends Component {
}

// Find all tabbables within node.
const tabbables = focus.tabbable.find( this.node );
const tabbables = focus.tabbable.find( this.node )
.filter( ( node ) => node !== this.node );
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure when this could be the case? Following the logic, find will call querySelectorAll, which shouldn't include the source node.


// If reversed (e.g. merge via backspace), use the last in the set of
// tabbables.
Expand Down
12 changes: 7 additions & 5 deletions editor/components/block-list/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ import BlockListBlock from './block';
import BlockSelectionClearer from '../block-selection-clearer';
import DefaultBlockAppender from '../default-block-appender';
import {
getMultiSelectedBlocksEndUid,
isSelectionEnabled,
isMultiSelecting,
getMultiSelectedBlocksStartUid,
getMultiSelectedBlocksEndUid,
} from '../../store/selectors';
import { startMultiSelect, stopMultiSelect, multiSelect, selectBlock } from '../../store/actions';

Expand Down Expand Up @@ -135,7 +136,7 @@ class BlockListLayout extends Component {
* @param {string} uid Block under cursor in multi-select drag.
*/
onSelectionChange( uid ) {
const { onMultiSelect, multiSelectionEndUID } = this.props;
const { onMultiSelect, selectionStart, selectionEnd } = this.props;
const { selectionAtStart } = this;
const isAtStart = selectionAtStart === uid;

Expand All @@ -145,12 +146,12 @@ class BlockListLayout extends Component {

// If multi-selecting and cursor extent returns to the start of
// selection, cancel multi-select.
if ( isAtStart && this.props.isMultiSelecting ) {
if ( isAtStart && selectionStart ) {
onMultiSelect( null, null );
}

// Expand multi-selection to block under cursor.
if ( ! isAtStart && multiSelectionEndUID !== uid ) {
if ( ! isAtStart && selectionEnd !== uid ) {
onMultiSelect( selectionAtStart, uid );
}
}
Expand Down Expand Up @@ -245,8 +246,9 @@ export default connect(
// Reference block selection value directly, since current selectors
// assume either multi-selection (getMultiSelectedBlocksStartUid) or
// singular-selection (getSelectedBlock) exclusively.
selectionStart: getMultiSelectedBlocksStartUid( state ),
selectionEnd: getMultiSelectedBlocksEndUid( state ),
selectionStartUID: state.blockSelection.start,
multiSelectionEndUID: getMultiSelectedBlocksEndUid( state ),
isSelectionEnabled: isSelectionEnabled( state ),
isMultiSelecting: isMultiSelecting( state ),
} ),
Expand Down