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

Apply block order by Flexbox order property #563

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 11 additions & 3 deletions editor/modes/visual-editor/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { connect } from 'react-redux';
import classnames from 'classnames';
import { Slot } from 'react-slot-fill';
import { partial } from 'lodash';
import { partial, get } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -186,7 +186,14 @@ class VisualEditorBlock extends wp.element.Component {
'is-hovered': isHovered,
} );

const { onSelect, onHover, onMouseLeave, onFocus, onInsertAfter } = this.props;
const {
onSelect,
onHover,
onMouseLeave,
onFocus,
onInsertAfter,
order,
} = this.props;

// Determine whether the block has props to apply to the wrapper
let wrapperProps;
Expand All @@ -209,8 +216,9 @@ class VisualEditorBlock extends wp.element.Component {
onMouseLeave={ onMouseLeave }
className={ className }
data-type={ block.blockType }
tabIndex="0"
tabIndex={ order }
{ ...wrapperProps }
style={ { ...get( wrapperProps, 'style' ), order } }
>
{ ( ( isSelected && ! isTyping ) || isHovered ) && <BlockMover uid={ block.uid } /> }
{ isSelected && ! isTyping &&
Expand Down
12 changes: 7 additions & 5 deletions editor/modes/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import { connect } from 'react-redux';
import { map } from 'lodash';

/**
* Internal dependencies
Expand All @@ -10,20 +11,21 @@ import './style.scss';
import Inserter from '../../inserter';
import VisualEditorBlock from './block';
import PostTitle from '../../post-title';
import { getBlockUids } from '../../selectors';

function VisualEditor( { blocks } ) {
return (
<div className="editor-visual-editor">
<PostTitle />
{ blocks.map( ( uid ) => (
<VisualEditorBlock key={ uid } uid={ uid } />
) ) }
<div className="editor-visual-editor__blocks">
{ map( blocks, ( block, uid ) => (
<VisualEditorBlock key={ uid } uid={ uid } />
) ) }
</div>
<Inserter />
</div>
);
}

export default connect( ( state ) => ( {
blocks: getBlockUids( state ),
blocks: state.editor.blocksByUid,
} ) )( VisualEditor );
5 changes: 5 additions & 0 deletions editor/modes/visual-editor/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
margin-right: auto;
}

.editor-visual-editor__blocks {
display: flex;
flex-direction: column;
}

.editor-visual-editor__block {
position: relative;
left: -#{ $block-padding + $block-mover-margin }; /* Make room for the mover */
Expand Down