Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Blocks: Reselect the current block if we click again on it
  • Loading branch information
youknowriad committed Apr 28, 2017
commit d95c03c0cf358af5c53762a3a4cf8a787d963199
8 changes: 3 additions & 5 deletions editor/modes/visual-editor/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,13 @@ class VisualEditorBlock extends wp.element.Component {
wrapperProps = settings.getEditWrapperProps( block.attributes );
}

// Disable reason: Each block can receive focus but must be able to contain
// block children. Tab keyboard navigation enabled by tabIndex assignment.
// Disable reason: Each block can be selected by clicking on it
Copy link
Member

Choose a reason for hiding this comment

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

The changes here break tab navigation:

  1. Focus text block
  2. Press tab

Expected: Image block is selected
Actual: Third block (next text block) is selected

The disable reason doesn't seem acceptable for accessibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 11d81e4

Copy link
Member

Choose a reason for hiding this comment

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

Should the comment be reverted back to its previous text? Or at least updated to reflect that it accepts focus? Seems like suggesting "clicking on it" as reason for disabling an accessibility rule is destined to... provoke response 😄


/* eslint-disable jsx-a11y/no-static-element-interactions */
/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role */
return (
<div
ref={ this.bindBlockNode }
tabIndex="0"
onFocus={ onSelect }
onClick={ onSelect }
onBlur={ this.maybeDeselect }
onKeyDown={ onStartTyping }
onMouseEnter={ onHover }
Expand Down
8 changes: 6 additions & 2 deletions editor/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,13 @@ export function selectedBlock( state = {}, action ) {
if ( ! action.selected ) {
return state.uid === action.uid ? {} : state;
}
return action.uid === state.uid
return action.uid === state.uid && ! state.typing
? state
: { uid: action.uid, typing: false, focus: {} };
: {
uid: action.uid,
typing: false,
focus: action.uid === state.uid ? state.focus : {}
};

case 'MOVE_BLOCK_UP':
case 'MOVE_BLOCK_DOWN':
Expand Down
19 changes: 17 additions & 2 deletions editor/test/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ describe( 'state', () => {
expect( state ).to.eql( { uid: 'kumquat', typing: false, focus: {} } );
} );

it( 'should not update the state if already selected', () => {
const original = deepFreeze( { uid: 'kumquat', typing: true, focus: {} } );
it( 'should not update the state if already selected and not typing', () => {
const original = deepFreeze( { uid: 'kumquat', typing: false, focus: {} } );
const state = selectedBlock( original, {
type: 'TOGGLE_BLOCK_SELECTED',
uid: 'kumquat',
Expand All @@ -269,6 +269,21 @@ describe( 'state', () => {
expect( state ).to.equal( original );
} );

it( 'should update the state if already selected and typing', () => {
const original = deepFreeze( { uid: 'kumquat', typing: true, focus: { editable: 'content' } } );
const state = selectedBlock( original, {
type: 'TOGGLE_BLOCK_SELECTED',
uid: 'kumquat',
selected: true
} );

expect( state ).to.eql( {
uid: 'kumquat',
typing: false,
focus: { editable: 'content' }
} );
} );

it( 'should unselect the block if currently selected', () => {
const original = deepFreeze( { uid: 'kumquat', typing: true, focus: {} } );
const state = selectedBlock( original, {
Expand Down