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

Fix switching between block types (paragraph, quote and heading) #109

Merged
merged 1 commit into from
Feb 21, 2017
Merged
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
7 changes: 2 additions & 5 deletions blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,12 +468,9 @@ function attachTypeSwitcherActions() {
} );

Object.keys( typeToTag ).forEach( function( type ) {
var selector = '.switch-block__block .type-icon-' + type;
var button = queryFirst( selector );
var label = queryFirst( selector + ' + label' );

var iconSelector = '.switch-block__block .type-icon-' + type;
var button = queryFirst( iconSelector ).parentNode;
Copy link
Member

Choose a reason for hiding this comment

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

Ah, at first I was going to suggest changing iconSelector to remove .type-icon-' + icon child selector, to avoid accessing parent node, but I see why it's needed to ensure that each icon has its own event bound. The alternative might be to bind a single event handler to the .switch-block__block button and determine at the time of click which icon type it contains. But this seems to work well and is a much more direct change 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, we could optimize using a single switch-block__block event handler. Let's keep it like this while prototyping :)

button.addEventListener( 'click', switchBlockType, false );
label.addEventListener( 'click', switchBlockType, false );

function switchBlockType( event ) {
if ( ! selectedBlock ) {
Expand Down